def test_without_language_field(self): """ Middleware should do nothing if the profile has no language field """ userena_settings.USERENA_LANGUAGE_FIELD = 'non_existant_language_field' user = User.objects.get(pk=1) req = self._get_request_with_user(user) # Middleware should do nothing UserenaLocaleMiddleware().process_request(req) self.failIf(hasattr(req, 'LANGUAGE_CODE'))
def test_without_language_field(self): """Middleware should do nothing if the profile has no language field""" userena_settings.USERENA_LANGUAGE_FIELD = "non_existant_language_field" user = User.objects.get(pk=1) req = self._get_request_with_user(user) # Middleware should do nothing UserenaLocaleMiddleware(get_response=get_response).process_request(req) self.assertFalse(hasattr(req, "LANGUAGE_CODE"))
def test_without_profile(self): """ Middleware should do nothing when a user has no profile """ # Delete the profile Profile.objects.get(pk=1).delete() user = User.objects.get(pk=1) # User shouldn't have a profile self.assertFalse(has_profile(user)) req = self._get_request_with_user(user) UserenaLocaleMiddleware().process_request(req) self.failIf(hasattr(req, 'LANGUAGE_CODE'))
def test_preference_user(self): """ Test the language preference of two users """ users = ((1, 'nl'), (2, 'en')) for pk, lang in users: user = User.objects.get(pk=pk) profile = get_user_profile(user=user) req = self._get_request_with_user(user) # Check that the user has this preference self.failUnlessEqual(profile.language, lang) # Request should have a ``LANGUAGE_CODE`` with dutch UserenaLocaleMiddleware().process_request(req) self.failUnlessEqual(req.LANGUAGE_CODE, lang)