Ejemplo n.º 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")
Ejemplo n.º 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')
Ejemplo n.º 3
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')
Ejemplo n.º 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)
     eq_(prefixer.get_language(), 'en-US')
Ejemplo n.º 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")
Ejemplo n.º 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.META.get("HTTP_ACCEPT_LANGUAGE"))
     prefixer = Prefixer(request)
     eq_(prefixer.get_language(), "en-US")
Ejemplo n.º 7
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')
Ejemplo n.º 8
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')
Ejemplo n.º 9
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")
Ejemplo n.º 10
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")
Ejemplo n.º 11
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')
Ejemplo n.º 12
0
    def process_request(self, request):
        # Exit early if we are not in the Facebook app section of the site to
        # avoid clashing with the Django auth middleware.
        if not in_facebook_app(request):
            return None

        # Default to an anonymous user.
        request.user = AnonymousFacebookUser()
        locale = None
        try:
            user = FacebookUser.objects.get(id=request.session[SESSION_KEY])
            request.user = user
            locale = user.locale
        except (FacebookUser.DoesNotExist, KeyError):
            pass

        if locale is None:
            # Since we can't get their locale from their user data, we'll use
            # funfactory's prefixer instead.
            prefixer = Prefixer(request)
            locale = prefixer.get_language()

        activate_locale(request, locale)