Ejemplo n.º 1
0
 def test_03_multilingual_middleware_get_lang_from_request(self):
     class Mock:
         pass
     
     middle = MultilingualURLMiddleware()
     
     
     with SettingsOverride(CMS_LANGUAGES = {'klingon':'Klingon'}):
         request = Mock()
         setattr(request, 'session', {})
         setattr(request,'path_info', '/en/whatever')
         setattr(request,'path', '/en/whatever')
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'en')
     
         setattr(request,'path_info', 'whatever')
         setattr(request,'path', 'whatever')
         setattr(request,'session', {'django_language':'klingon'})
         setattr(request,'COOKIES', {})
         setattr(request,'META', {})
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'klingon') # the session's language. Nerd.
         
         request = Mock()
         setattr(request,'path_info', 'whatever')
         setattr(request,'path', 'whatever')
         setattr(request,'COOKIES', {'django_language':'klingon'})
         setattr(request,'META', {})
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'klingon') # the cookies language.
         
         # Now the following should revert to the default language (en)
         setattr(request,'COOKIES', {'django_language':'elvish'})
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'en') # The default
Ejemplo n.º 2
0
    def test_03_multilingual_middleware_get_lang_from_request(self):
        class Mock:
            pass

        middle = MultilingualURLMiddleware()

        with SettingsOverride(CMS_LANGUAGES={'klingon': 'Klingon'}):
            request = Mock()
            setattr(request, 'session', {})
            setattr(request, 'path_info', '/en/whatever')
            setattr(request, 'path', '/en/whatever')
            result = middle.get_language_from_request(request)
            self.assertEqual(result, 'en')

            setattr(request, 'path_info', 'whatever')
            setattr(request, 'path', 'whatever')
            setattr(request, 'session', {'django_language': 'klingon'})
            setattr(request, 'COOKIES', {})
            setattr(request, 'META', {})
            result = middle.get_language_from_request(request)
            self.assertEqual(result,
                             'klingon')  # the session's language. Nerd.

            request = Mock()
            setattr(request, 'path_info', 'whatever')
            setattr(request, 'path', 'whatever')
            setattr(request, 'COOKIES', {'django_language': 'klingon'})
            setattr(request, 'META', {})
            result = middle.get_language_from_request(request)
            self.assertEqual(result, 'klingon')  # the cookies language.

            # Now the following should revert to the default language (en)
            setattr(request, 'COOKIES', {'django_language': 'elvish'})
            result = middle.get_language_from_request(request)
            self.assertEqual(result, 'en')  # The default
Ejemplo n.º 3
0
 def test_multilingual_middleware_get_lang_from_request(self):
     
     middle = MultilingualURLMiddleware()
     
     FRENCH = 'fr'
     ELVISH = 'x-elvish'
     
     with SettingsOverride(CMS_LANGUAGES=((FRENCH, 'French'),("it", "Italian")), CMS_FRONTEND_LANGUAGES=(FRENCH,)):
         request = AttributeObject(
             session={},
             path_info='/it/whatever',
             path='/it/whatever',
             COOKIES={},
             META={},
         )
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'en')#falls back to default
         
         
         request = AttributeObject(
             session={
                 'django_language': FRENCH,
             },
             path_info='whatever',
             path='whatever',
             COOKIES={},
             META={},
         )
         result = middle.get_language_from_request(request)
         self.assertEqual(result, FRENCH) # the session's language.
         
         
         request = AttributeObject(
             path_info='whatever',
             path='whatever',
             COOKIES={
                 'django_language': FRENCH,
             },
             META={},
         )
         result = middle.get_language_from_request(request)
         self.assertEqual(result, FRENCH) # the cookies language.
         
         # Now the following should revert to the default language (en)
         request.COOKIES['django_language'] = ELVISH
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'en') # The default
Ejemplo n.º 4
0
    def test_multilingual_middleware_get_lang_from_request(self):

        middle = MultilingualURLMiddleware()

        FRENCH = 'fr'
        ELVISH = 'x-elvish'

        with SettingsOverride(CMS_LANGUAGES=((FRENCH, 'French'), ("it",
                                                                  "Italian")),
                              CMS_FRONTEND_LANGUAGES=(FRENCH, )):
            request = AttributeObject(
                session={},
                path_info='/it/whatever',
                path='/it/whatever',
                COOKIES={},
                META={},
            )
            result = middle.get_language_from_request(request)
            self.assertEqual(result, 'en')  #falls back to default

            request = AttributeObject(
                session={
                    'django_language': FRENCH,
                },
                path_info='whatever',
                path='whatever',
                COOKIES={},
                META={},
            )
            result = middle.get_language_from_request(request)
            self.assertEqual(result, FRENCH)  # the session's language.

            request = AttributeObject(
                path_info='whatever',
                path='whatever',
                COOKIES={
                    'django_language': FRENCH,
                },
                META={},
            )
            result = middle.get_language_from_request(request)
            self.assertEqual(result, FRENCH)  # the cookies language.

            # Now the following should revert to the default language (en)
            request.COOKIES['django_language'] = ELVISH
            result = middle.get_language_from_request(request)
            self.assertEqual(result, 'en')  # The default
Ejemplo n.º 5
0
 def test_multilingual_middleware_get_lang_from_request(self):
     
     middle = MultilingualURLMiddleware()
     
     KLINGON = 'x-klingon'
     ELVISH = 'x-elvish'
     
     with SettingsOverride(CMS_LANGUAGES=((KLINGON, 'Klingon'),)):
         request = AttributeObject(
             session={},
             path_info='/en/whatever',
             path='/en/whatever'
         )
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'en')
         
         
         request = AttributeObject(
             session={
                 'django_language': KLINGON,
             },
             path_info='whatever',
             path='whatever',
             COOKIES={},
             META={},
         )
         result = middle.get_language_from_request(request)
         self.assertEqual(result, KLINGON) # the session's language. Nerd.
         
         
         request = AttributeObject(
             path_info='whatever',
             path='whatever',
             COOKIES={
                 'django_language': KLINGON,
             },
             META={},
         )
         result = middle.get_language_from_request(request)
         self.assertEqual(result, KLINGON) # the cookies language.
         
         # Now the following should revert to the default language (en)
         request.COOKIES['django_language'] = ELVISH
         result = middle.get_language_from_request(request)
         self.assertEqual(result, 'en') # The default
Ejemplo n.º 6
0
    def test_multilingual_middleware_get_lang_from_request(self):

        middle = MultilingualURLMiddleware()

        KLINGON = 'x-klingon'
        ELVISH = 'x-elvish'

        with SettingsOverride(CMS_LANGUAGES=((KLINGON, 'Klingon'), )):
            request = AttributeObject(session={},
                                      path_info='/en/whatever',
                                      path='/en/whatever')
            result = middle.get_language_from_request(request)
            self.assertEqual(result, 'en')

            request = AttributeObject(
                session={
                    'django_language': KLINGON,
                },
                path_info='whatever',
                path='whatever',
                COOKIES={},
                META={},
            )
            result = middle.get_language_from_request(request)
            self.assertEqual(result, KLINGON)  # the session's language. Nerd.

            request = AttributeObject(
                path_info='whatever',
                path='whatever',
                COOKIES={
                    'django_language': KLINGON,
                },
                META={},
            )
            result = middle.get_language_from_request(request)
            self.assertEqual(result, KLINGON)  # the cookies language.

            # Now the following should revert to the default language (en)
            request.COOKIES['django_language'] = ELVISH
            result = middle.get_language_from_request(request)
            self.assertEqual(result, 'en')  # The default