The existing pattern of using `override_settings(MODULESTORE=...)` prevented
us from having more than one layer of subclassing in modulestore tests.
In a structure like:
@override_settings(MODULESTORE=store_a)
class BaseTestCase(ModuleStoreTestCase):
def setUp(self):
# use store
@override_settings(MODULESTORE=store_b)
class ChildTestCase(BaseTestCase):
def setUp(self):
# use store
In this case, the store actions performed in `BaseTestCase` on behalf of
`ChildTestCase` would still use `store_a`, even though the `ChildTestCase`
had specified to use `store_b`. This is because the `override_settings`
decorator would be the innermost wrapper around the `BaseTestCase.setUp` method,
no matter what `ChildTestCase` does.
To remedy this, we move the call to `override_settings` into the
`ModuleStoreTestCase.setUp` method, and use a cleanup to remove the override.
Subclasses can just defined the `MODULESTORE` class attribute to specify which
modulestore to use _for the entire `setUp` chain_.
[PLAT-419]
28 lines
902 B
Python
28 lines
902 B
Python
"""
|
|
Tests i18n in courseware
|
|
"""
|
|
import re
|
|
|
|
from django.test import TestCase
|
|
from django.test.utils import override_settings
|
|
|
|
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
|
|
|
|
|
|
@override_settings(LANGUAGES=(('eo', 'Esperanto'),))
|
|
class I18nTestCase(TestCase):
|
|
"""
|
|
Tests for i18n
|
|
"""
|
|
def test_default_is_en(self):
|
|
response = self.client.get('/')
|
|
self.assertIn('<html lang="en">', response.content)
|
|
self.assertEqual(response['Content-Language'], 'en')
|
|
self.assertTrue(re.search('<body.*class=".*lang_en">', response.content))
|
|
|
|
def test_esperanto(self):
|
|
response = self.client.get('/', HTTP_ACCEPT_LANGUAGE='eo')
|
|
self.assertIn('<html lang="eo">', response.content)
|
|
self.assertEqual(response['Content-Language'], 'eo')
|
|
self.assertTrue(re.search('<body.*class=".*lang_eo">', response.content))
|