Пример #1
0
 def test_get_language_valid_lang_param(self):
     """
     Should return lang param value if it is in settings.LANGUAGE_URL_MAP
     """
     request = self.factory.get('/?lang=de')
     eq_(request.GET.get('lang'), 'de')
     ok_('de' in settings.LANGUAGE_URL_MAP)
     prefixer = Prefixer(request)
     eq_(prefixer.get_language(), 'de')
Пример #2
0
 def test_get_language_valid_lang_param(self):
     """
     Should return lang param value if it is in settings.LANGUAGE_URL_MAP
     """
     request = self.factory.get('/?lang=de')
     eq_(request.GET.get('lang'), 'de')
     ok_('de' in settings.LANGUAGE_URL_MAP)
     prefixer = Prefixer(request)
     eq_(prefixer.get_language(), 'de')
Пример #3
0
 def test_get_language_default_language_code(self):
     """
     Should return default set by settings.LANGUAGE_CODE if no 'lang'
     url parameter and no Accept-Language header
     """
     request = self.factory.get('/')
     self.assertFalse('lang' in request.GET)
     self.assertFalse(request.META.get('HTTP_ACCEPT_LANGUAGE'))
     prefixer = Prefixer(request)
     assert prefixer.get_language() == 'en-US'
Пример #4
0
 def test_get_language_default_language_code(self):
     """
     Should return default set by settings.LANGUAGE_CODE if no 'lang'
     url parameter and no Accept-Language header
     """
     request = self.factory.get('/')
     self.assertFalse('lang' in request.GET)
     self.assertFalse(request.META.get('HTTP_ACCEPT_LANGUAGE'))
     prefixer = Prefixer(request)
     assert prefixer.get_language() == 'en-US'
Пример #5
0
 def test_get_language_invalid_lang_param(self):
     """
     Should return default set by settings.LANGUAGE_CODE if lang
     param value is not in settings.LANGUAGE_URL_MAP
     """
     request = self.factory.get('/?lang=de')
     ok_('lang' in request.GET)
     self.assertFalse('de' in settings.LANGUAGE_URL_MAP)
     prefixer = Prefixer(request)
     eq_(prefixer.get_language(), 'en-US')
Пример #6
0
 def test_get_language_default_language_code(self):
     """
     Should return default set by settings.LANGUAGE_CODE if no 'lang'
     url parameter and no Accept-Language header
     """
     request = self.factory.get("/")
     self.assertFalse("lang" in request.GET)
     self.assertFalse(request.headers.get("Accept-Language"))
     prefixer = Prefixer(request)
     assert prefixer.get_language() == "en-US"
Пример #7
0
 def test_get_language_invalid_lang_param(self):
     """
     Should return default set by settings.LANGUAGE_CODE if lang
     param value is not in settings.LANGUAGE_URL_MAP
     """
     request = self.factory.get('/?lang=de')
     ok_('lang' in request.GET)
     self.assertFalse('de' in settings.LANGUAGE_URL_MAP)
     prefixer = Prefixer(request)
     eq_(prefixer.get_language(), 'en-US')
Пример #8
0
 def test_get_language_default_language_code(self):
     """
     Should return default set by settings.LANGUAGE_CODE if no 'lang'
     url parameter and no Accept-Language header
     """
     request = self.factory.get("/")
     self.assertFalse("lang" in request.GET)
     self.assertFalse(request.META.get("HTTP_ACCEPT_LANGUAGE"))
     prefixer = Prefixer(request)
     eq_(prefixer.get_language(), "en-US")
Пример #9
0
 def test_get_language_no_best(self):
     """
     Should return default set by settings.LANGUAGE_CODE if
     get_best_language return value is None
     """
     request = self.factory.get('/')
     request.META['HTTP_ACCEPT_LANGUAGE'] = 'de, es'
     prefixer = Prefixer(request)
     prefixer.get_best_language = Mock(return_value=None)
     assert prefixer.get_language() == 'en-US'
     prefixer.get_best_language.assert_called_once_with('de, es')
Пример #10
0
 def test_get_language_returns_best(self):
     """
     Should pass Accept-Language header value to get_best_language
     and return result
     """
     request = self.factory.get('/')
     request.META['HTTP_ACCEPT_LANGUAGE'] = 'de, es'
     prefixer = Prefixer(request)
     prefixer.get_best_language = Mock(return_value='de')
     assert prefixer.get_language() == 'de'
     prefixer.get_best_language.assert_called_once_with('de, es')
Пример #11
0
 def test_get_language_no_best(self):
     """
     Should return default set by settings.LANGUAGE_CODE if
     get_best_language return value is None
     """
     request = self.factory.get('/')
     request.META['HTTP_ACCEPT_LANGUAGE'] = 'de, es'
     prefixer = Prefixer(request)
     prefixer.get_best_language = Mock(return_value=None)
     assert prefixer.get_language() == 'en-US'
     prefixer.get_best_language.assert_called_once_with('de, es')
Пример #12
0
 def test_get_language_returns_best(self):
     """
     Should pass Accept-Language header value to get_best_language
     and return result
     """
     request = self.factory.get('/')
     request.META['HTTP_ACCEPT_LANGUAGE'] = 'de, es'
     prefixer = Prefixer(request)
     prefixer.get_best_language = Mock(return_value='de')
     assert prefixer.get_language() == 'de'
     prefixer.get_best_language.assert_called_once_with('de, es')
Пример #13
0
 def test_get_language_returns_best(self):
     """
     Should pass Accept-Language header value to get_best_language
     and return result
     """
     request = self.factory.get("/")
     request.META["HTTP_ACCEPT_LANGUAGE"] = "de, es"
     prefixer = Prefixer(request)
     prefixer.get_best_language = Mock(return_value="de")
     assert prefixer.get_language() == "de"
     prefixer.get_best_language.assert_called_once_with("de, es")
Пример #14
0
 def test_get_language_returns_best(self):
     """
     Should pass Accept-Language header value to get_best_language
     and return result
     """
     request = self.factory.get("/")
     request.META["HTTP_ACCEPT_LANGUAGE"] = "de, es"
     prefixer = Prefixer(request)
     prefixer.get_best_language = Mock(return_value="de")
     eq_(prefixer.get_language(), "de")
     prefixer.get_best_language.assert_called_once_with("de, es")
Пример #15
0
 def test_get_language_no_best(self):
     """
     Should return default set by settings.LANGUAGE_CODE if
     get_best_language return value is None
     """
     request = self.factory.get("/")
     request.META["HTTP_ACCEPT_LANGUAGE"] = "de, es"
     prefixer = Prefixer(request)
     prefixer.get_best_language = Mock(return_value=None)
     eq_(prefixer.get_language(), "en-US")
     prefixer.get_best_language.assert_called_once_with("de, es")