Add tests for babybuddy app code.

This commit is contained in:
Christopher Charbonneau Wells 2017-11-12 19:43:40 -05:00
parent 60ac9a7f5d
commit bd2655166e
3 changed files with 83 additions and 0 deletions

View File

@ -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.')

View File

@ -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)

View File

@ -47,3 +47,11 @@ class ViewsTestCase(TestCase):
) )
page = self.c.get('/') page = self.c.get('/')
self.assertEqual(page.url, '/dashboard/') 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)