Add basic translation feature tests.

This commit is contained in:
Christopher C. Wells 2019-04-18 19:52:17 -07:00
parent c3224675a2
commit 13a0424fc2
3 changed files with 76 additions and 10 deletions

View File

@ -25,6 +25,14 @@ class FormsTestCase(TestCase):
cls.user = User.objects.create_user( cls.user = User.objects.create_user(
is_superuser=True, **cls.credentials) is_superuser=True, **cls.credentials)
cls.settings_template = {
'first_name': 'User',
'last_name': 'Name',
'email': 'user@user.user',
'dashboard_refresh_rate': '',
'language': 'en'
}
def test_change_password(self): def test_change_password(self):
self.c.login(**self.credentials) self.c.login(**self.credentials)
@ -85,18 +93,28 @@ class FormsTestCase(TestCase):
def test_user_settings(self): def test_user_settings(self):
self.c.login(**self.credentials) self.c.login(**self.credentials)
params = { params = self.settings_template.copy()
'first_name': 'User', params['first_name'] = 'New First Name'
'last_name': 'Name',
'email': 'user@user.user',
'dashboard_refresh_rate': ''
}
page = self.c.post('/user/settings/', params) page = self.c.post('/user/settings/', params, follow=True)
self.assertEqual(page.status_code, 302) self.assertEqual(page.status_code, 200)
self.assertContains(page, 'New First Name')
def test_user_settings_invalid(self):
self.c.login(**self.credentials)
params = self.settings_template.copy()
params['email'] = 'Not an email address'
params = {'email': 'Not an email address'}
page = self.c.post('/user/settings/', params) page = self.c.post('/user/settings/', params)
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
self.assertFormError(page, 'user_form', 'email', self.assertFormError(page, 'user_form', 'email',
'Enter a valid email address.') 'Enter a valid email address.')
def test_user_settings_language(self):
self.c.login(**self.credentials)
params = self.settings_template.copy()
params['language'] = 'fr'
page = self.c.post('/user/settings/', data=params, follow=True)
self.assertContains(page, 'Paramètres Utilisateur')

View File

@ -17,10 +17,13 @@ class SettingsTestCase(TestCase):
} }
user = User.objects.create_user(is_superuser=True, **credentials) user = User.objects.create_user(is_superuser=True, **credentials)
self.assertIsInstance(user.settings, Settings) self.assertIsInstance(user.settings, Settings)
self.assertEqual(str(user.settings), 'Test\'s Settings')
self.assertEqual( self.assertEqual(
user.settings.dashboard_refresh_rate_milliseconds, 60000) user.settings.dashboard_refresh_rate_milliseconds, 60000)
user.settings.dashboard_refresh_rate = None user.settings.dashboard_refresh_rate = None
user.save() user.save()
self.assertIsNone(user.settings.dashboard_refresh_rate_milliseconds) self.assertIsNone(user.settings.dashboard_refresh_rate_milliseconds)
user.settings.language = 'fr'
user.save()
self.assertEqual(user.settings.language, 'fr')

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.test import Client as HttpClient
from django.contrib.auth.models import User
from django.core.management import call_command
from faker import Factory
class TranslationTestCase(TestCase):
@classmethod
def setUpClass(cls):
super(TranslationTestCase, cls).setUpClass()
fake = Factory.create()
call_command('migrate', 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.params_template = {
'first_name': 'User',
'last_name': 'Name',
'email': 'user@user.user',
'dashboard_refresh_rate': '',
'language': 'en'
}
cls.c.login(**cls.credentials)
def test_translation_fr(self):
params = self.params_template.copy()
params['language'] = 'fr'
page = self.c.post('/user/settings/', data=params, follow=True)
self.assertContains(page, 'Paramètres Utilisateur')
page = self.c.get('/welcome/')
self.assertContains(page, 'Bienvenue à Baby Buddy!')