diff --git a/babybuddy/tests/tests_forms.py b/babybuddy/tests/tests_forms.py new file mode 100644 index 00000000..880b66d2 --- /dev/null +++ b/babybuddy/tests/tests_forms.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from django.core.management import call_command +from django.test import TestCase +from django.test import Client as HttpClient + +from faker import Factory + + +class FormsTestCase(TestCase): + @classmethod + def setUpClass(cls): + super(FormsTestCase, cls).setUpClass() + fake = Factory.create() + call_command('migrate', verbosity=0) + call_command('fake', verbosity=0) + + cls.c = HttpClient() + + fake_user = fake.simple_profile() + cls.credentials = { + 'username': fake_user['username'], + 'password': fake.password() + } + cls.user = User.objects.create_user( + is_superuser=True, **cls.credentials) + + cls.c.login(**cls.credentials) + + def test_user_settings(self): + params = { + 'first_name': 'User', + 'last_name': 'Name', + 'email': 'user@user.user', + 'dashboard_refresh_rate': '' + } + + page = self.c.post('/user/settings/', params) + self.assertEqual(page.status_code, 302) + + params = {'email': 'Not an email address'} + page = self.c.post('/user/settings/', params) + self.assertEqual(page.status_code, 200) + self.assertFormError(page, 'user_form', 'email', + 'Enter a valid email address.') diff --git a/babybuddy/tests/tests_models.py b/babybuddy/tests/tests_models.py new file mode 100644 index 00000000..afd80713 --- /dev/null +++ b/babybuddy/tests/tests_models.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from django.core.management import call_command +from django.test import TestCase + +from babybuddy.models import Settings + + +class SettingsTestCase(TestCase): + def setUp(self): + call_command('migrate', verbosity=0) + + def test_settings(self): + credentials = { + 'username': 'Test', + 'password': 'User' + } + user = User.objects.create_user(is_superuser=True, **credentials) + self.assertIsInstance(user.settings, Settings) + self.assertEqual(str(user.settings), 'Test\'s Settings') + self.assertEqual( + user.settings.dashboard_refresh_rate_milliseconds, 60000) + + user.settings.dashboard_refresh_rate = None + user.save() + self.assertIsNone(user.settings.dashboard_refresh_rate_milliseconds) diff --git a/babybuddy/tests/tests_views.py b/babybuddy/tests/tests_views.py index bf048202..b4bc6470 100644 --- a/babybuddy/tests/tests_views.py +++ b/babybuddy/tests/tests_views.py @@ -47,3 +47,11 @@ class ViewsTestCase(TestCase): ) page = self.c.get('/') self.assertEqual(page.url, '/dashboard/') + + def test_user_settings(self): + page = self.c.get('/user/settings/') + self.assertEqual(page.status_code, 200) + + def test_welcome(self): + page = self.c.get('/welcome/') + self.assertEqual(page.status_code, 200)