Using Django 1.3, Python 2.6
Having a particularly strange tracking issue related to internationalization and RequestFactory vs. TestClient for testing Views.
If I run:
./manage.py test
All tests are performed (including problem tests) and pass successfully. If I run:
./manage.py test <appname>
Application tests will fail, throwing an exception to the template for templates that use language code, because the django language thinks the request is asking, is not the language that we list in settings.LANGUAGES. (In this case, it was always "en-us", the cabinet-matching language with which we support "en")
Here is an example of a test that will fail:
class TemplateServingTestCase(TestCase): def setUp(self): self.app_dir = os.path.abspath(os.path.dirname(__file__)) self.gallery_root = os.path.join(self.app_dir, 'test_gallery') self.gallery_url = '/' self.request = RequestFactory().get('/') def test_404_invalid_category(self): self.assertRaises(Http404, gallery_page, self.request, 'bad-category', self.gallery_root, self.gallery_url )
This problem does not occur if django TestClient is used to create a request URL that invokes a specific view. However, if this view is simply invoked with the result of the RequestFactory get or put methods, it will raise the error above.
It seems that using the RequestFactory method, the settings file is not respected. Did I miss something simple here?
Additional Information
Applicable locale settings
LANGUAGE_CODE = 'en' LANGUAGES = ( ('en', 'English'), ('de', 'Deutsch'), ('es', 'Espanol'), ('fr', 'Francaise'), ('it', 'Italiano'), ('pt-br', 'Portugues (Brasil)'), )
Active middleware
MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.locale.LocaleMiddleware', 'services.middleware.LegacyIntegrationMiddleware', )