示例#1
0
    def test_multilingual_middleware_handles_redirections(self):

        middle = MultilingualURLMiddleware()

        request = AttributeObject(session={},
                                  path_info='whatever',
                                  path='whatever',
                                  COOKIES={
                                      'django_language': 'en',
                                  },
                                  META={},
                                  LANGUAGE_CODE='en')

        # Don't re-prefix
        response = middle.process_response(
            request, HttpResponseRedirect('/en/some-path/'))
        self.assertTrue(response['Location'] == '/en/some-path/')

        response = middle.process_response(
            request, HttpResponseRedirect('%ssome-path/' % settings.MEDIA_URL))
        self.assertTrue(response['Location'] == '%ssome-path/' %
                        settings.MEDIA_URL)

        response = middle.process_response(
            request,
            HttpResponseRedirect('%ssome-path/' % settings.STATIC_URL))
        self.assertTrue(response['Location'] == '%ssome-path/' %
                        settings.STATIC_URL)

        # Prefix
        response = middle.process_response(
            request, HttpResponseRedirect('/xx/some-path/'))
        self.assertTrue(response['Location'] == '/en/xx/some-path/')
示例#2
0
    def test_multilingual_middleware_handles_redirections(self):

        middle = MultilingualURLMiddleware()

        request = AttributeObject(
            session={},
            path_info='whatever',
            path='whatever',
            COOKIES={
                'django_language': 'en',
            },
            META = {},
            LANGUAGE_CODE = 'en'
        )
        
        # Don't re-prefix
        response = middle.process_response(request,HttpResponseRedirect('/en/some-path/'))
        self.assertTrue(response['Location'] == '/en/some-path/')

        response = middle.process_response(request,HttpResponseRedirect('%ssome-path/'%settings.MEDIA_URL))
        self.assertTrue(response['Location'] == '%ssome-path/' %settings.MEDIA_URL)

        response = middle.process_response(request,HttpResponseRedirect('%ssome-path/'%settings.STATIC_URL))
        self.assertTrue(response['Location'] == '%ssome-path/' %settings.STATIC_URL)
        

        # Prefix
        response = middle.process_response(request,HttpResponseRedirect('/xx/some-path/'))
        self.assertTrue(response['Location'] == '/en/xx/some-path/')
示例#3
0
    def test_14_multilingual_urls_point_to_original_language_when_not_redirecting(
            self):
        """
        When using the fallback language for a request, the replaced urls point to
        the requsted, instead of the fallback language.
        """
        from cms.views import details
        middleware = MultilingualURLMiddleware()
        requested_language = settings.LANGUAGES[1][0]
        fallback_language = settings.LANGUAGES[0][0]

        test_settings = dict(CMS_TEMPLATES=((TEMPLATE_NAME, ''), ),
                             CMS_LANGUAGE_FALLBACK='no_redirect')

        with SettingsOverride(**test_settings):
            instance, plugin_class = CMSPlugin.objects.all(
            )[0].get_plugin_instance()
            instance.body = '<a href="/slug/">fnord</a>'
            instance.save()
            request = self.get_request(path="/fr/renderingtestcase-slug ",
                                       language=requested_language)
            middleware.process_request(request)
            response = details(request, slug=self.test_page.get_slug())
            response = middleware.process_response(request, response)
            self.assertContains(response, '/%s/slug' % requested_language)
            self.assertNotContains(response, '/%s/slug' % fallback_language)
示例#4
0
    def test_form_multilingual(self):
        """
        Tests for correct form URL mangling
        """
        language = 'en'
        pages_root = self.get_pages_root()
        middle = MultilingualURLMiddleware()
        request = self.get_request(pages_root,language=language)

        html = '<form action="%sfoo/bar/"> </form>' % pages_root
        response = middle.process_response(request,HttpResponse(html))
        self.assertContains(response,'/%s%sfoo/bar/' % (language,pages_root))
        self.assertContains(response,'/en/content/foo/bar/')
示例#5
0
    def test_form_multilingual(self):
        """
        Tests for correct form URL mangling
        """
        language = 'en'
        pages_root = self.get_pages_root()
        middle = MultilingualURLMiddleware()
        request = self.get_request(pages_root, language=language)

        html = '<form action="%sfoo/bar/"> </form>' % pages_root
        response = middle.process_response(request, HttpResponse(html))
        self.assertContains(response, '/%s%sfoo/bar/' % (language, pages_root))
        self.assertContains(response, '/en/content/foo/bar/')
示例#6
0
    def test_multilingual_middleware_ignores_static_url(self):

        middle = MultilingualURLMiddleware()
        KLINGON = 'x-klingon'

        with SettingsOverride(CMS_LANGUAGES=((KLINGON, 'Klingon'), )):
            request = AttributeObject(session={},
                                      path_info='whatever',
                                      path='whatever',
                                      COOKIES={
                                          'django_language': KLINGON,
                                      },
                                      META={},
                                      LANGUAGE_CODE=KLINGON)
            html = """<ul>
                <li><a href="/some-page/">some page</a></li>
                <li><a href="%simages/some-media-file.jpg">some media file</a></li>
                <li><a href="%simages/some-static-file.jpg">some static file</a></li>
                <li><a href="%simages/some-admin-file.jpg">some admin media file</a></li>
                <li><a href="%simages/some-other-file.jpg">some static file</a></li>
                </ul>""" % (
                settings.MEDIA_URL,
                settings.STATIC_URL,
                settings.ADMIN_MEDIA_PREFIX,
                '/some-path/',
            )

            response = middle.process_response(request, HttpResponse(html))

            # These paths shall be prefixed
            self.assertTrue('href="/%s/some-page/' %
                            KLINGON in response.content)
            self.assertTrue('href="/%s%simages/some-other-file.jpg' %
                            (KLINGON, '/some-path/') in response.content)

            # These shall not
            self.assertTrue('href="%simages/some-media-file.jpg' %
                            settings.MEDIA_URL in response.content)
            self.assertTrue('href="%simages/some-static-file.jpg' %
                            settings.STATIC_URL in response.content)
            self.assertTrue('href="%simages/some-admin-file.jpg' %
                            settings.ADMIN_MEDIA_PREFIX in response.content)
示例#7
0
    def test_multilingual_middleware_ignores_static_url(self):

        middle = MultilingualURLMiddleware()
        FRENCH = 'x-FRENCH'
        
        with SettingsOverride(CMS_LANGUAGES=((FRENCH, 'FRENCH'),)):
            request = AttributeObject(
                session={},
                path_info='whatever',
                path='whatever',
                COOKIES={
                    'django_language': FRENCH,
                },
                META = {},
                LANGUAGE_CODE = FRENCH
            )
            html = """<ul>
                <li><a href="/some-page/">some page</a></li>
                <li><a href="%simages/some-media-file.jpg">some media file</a></li>
                <li><a href="%simages/some-static-file.jpg">some static file</a></li>
                <li><a href="%simages/some-admin-file.jpg">some admin media file</a></li>
                <li><a href="%simages/some-other-file.jpg">some static file</a></li>
                </ul>""" %(
                    settings.MEDIA_URL,
                    settings.STATIC_URL,
                    admin_static_url(),
                    '/some-path/',
                )
            
            response = middle.process_response(request,HttpResponse(html))
            
            # These paths shall be prefixed
            self.assertTrue('href="/%s/some-page/' %FRENCH in response.content)
            self.assertTrue('href="/%s%simages/some-other-file.jpg' %(FRENCH, '/some-path/') in response.content)

            # These shall not
            self.assertTrue('href="%simages/some-media-file.jpg' %settings.MEDIA_URL in response.content)
            self.assertTrue('href="%simages/some-static-file.jpg' %settings.STATIC_URL in response.content)            
            self.assertTrue('href="%simages/some-admin-file.jpg' %admin_static_url() in response.content)
示例#8
0
    def test_14_multilingual_urls_point_to_original_language_when_not_redirecting(self):
        """
        When using the fallback language for a request, the replaced urls point to
        the requsted, instead of the fallback language.
        """
        from cms.views import details

        middleware = MultilingualURLMiddleware()
        requested_language = settings.LANGUAGES[1][0]
        fallback_language = settings.LANGUAGES[0][0]

        test_settings = dict(CMS_TEMPLATES=((TEMPLATE_NAME, ""),), CMS_LANGUAGE_FALLBACK="no_redirect")

        with SettingsOverride(**test_settings):
            instance, plugin_class = CMSPlugin.objects.all()[0].get_plugin_instance()
            instance.body = '<a href="/slug/">fnord</a>'
            instance.save()
            request = self.get_request(path="/fr/renderingtestcase-slug ", language=requested_language)
            middleware.process_request(request)
            response = details(request, slug=self.test_page.get_slug())
            response = middleware.process_response(request, response)
            self.assertContains(response, "/%s/slug" % requested_language)
            self.assertNotContains(response, "/%s/slug" % fallback_language)