コード例 #1
0
 def test_find_selected(self):
     subchild = AttributeObject()
     firstchild = AttributeObject(ancestor=True, children=[subchild])
     selectedchild = AttributeObject(selected=True)
     secondchild = AttributeObject(ancestor=True, children=[selectedchild])
     root = AttributeObject(ancestor=True, children=[firstchild, secondchild])
     nodes = [root]
     selected = find_selected(nodes)
     self.assertEqual(selected, selectedchild)
コード例 #2
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_no_moderator(self):
     with SettingsOverride(CMS_MODERATOR=True):
         control = AttributeObject()
         contribute_list_filter(control)
     with SettingsOverride(CMS_MODERATOR=False):
         experiment = AttributeObject()
         contribute_list_filter(experiment)
     self.assertTrue('moderator_state' in control.list_filter,
                     control.list_filter)
     self.assertFalse('moderator_state' in experiment.list_filter,
                      experiment.list_filter)
コード例 #3
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_no_menu_title_overwrite(self):
     with SettingsOverride(CMS_MENU_TITLE_OVERWRITE=True):
         control = AttributeObject()
         contribute_fieldsets(control)
     with SettingsOverride(CMS_MENU_TITLE_OVERWRITE=False):
         experiment = AttributeObject()
         contribute_fieldsets(experiment)
     self.validate_attributes(control, experiment,
                              ['fieldsets', 'general_fields'])
     self.assertEqual(control.general_fields[0], ('title', 'menu_title'))
     self.assertEqual(experiment.general_fields[0], 'title')
コード例 #4
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_no_softroot(self):
     with SettingsOverride(CMS_SOFTROOT=True):
         control = AttributeObject()
         contribute_fieldsets(control)
     with SettingsOverride(CMS_SOFTROOT=False):
         experiment = AttributeObject()
         contribute_fieldsets(experiment)
     self.validate_attributes(control, experiment,
                              ['fieldsets', 'advanced_fields'])
     self.assertTrue('soft_root' in control.advanced_fields)
     self.assertFalse('soft_root' in experiment.advanced_fields)
コード例 #5
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_no_softroot(self):
     with SettingsOverride(CMS_SOFTROOT=True):
         control = AttributeObject()
         contribute_list_filter(control)
     with SettingsOverride(CMS_SOFTROOT=False):
         experiment = AttributeObject()
         contribute_list_filter(experiment)
     self.assertTrue('soft_root' in control.list_filter,
                     control.list_filter)
     self.assertFalse('soft_root' in experiment.list_filter,
                      experiment.list_filter)
コード例 #6
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_no_moderator(self):
     with SettingsOverride(CMS_MODERATOR=True):
         control = AttributeObject()
         contribute_fieldsets(control)
     with SettingsOverride(CMS_MODERATOR=False):
         nomod = AttributeObject()
         contribute_fieldsets(nomod)
     self.validate_attributes(control, nomod,
                              ['fieldsets', 'additional_hidden_fields'])
     self.assertEqual(control.additional_hidden_fields,
                      ['moderator_state', 'moderator_message'])
     self.assertEqual(nomod.additional_hidden_fields, [])
コード例 #7
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_no_seo(self):
     with SettingsOverride(CMS_SEO_FIELDS=True):
         control = AttributeObject()
         contribute_fieldsets(control)
     with SettingsOverride(CMS_SEO_FIELDS=False):
         experiment = AttributeObject()
         contribute_fieldsets(experiment)
     self.validate_attributes(control, experiment,
                              ['fieldsets', 'seo_fields'])
     self.assertEqual(control.seo_fields,
                      ['page_title', 'meta_description', 'meta_keywords'])
     self.assertFalse(experiment.seo_fields, [])
コード例 #8
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_redirects(self):
     with SettingsOverride(CMS_REDIRECTS=False):
         control = AttributeObject()
         contribute_fieldsets(control)
     with SettingsOverride(CMS_REDIRECTS=True):
         experiment = AttributeObject()
         contribute_fieldsets(experiment)
     self.validate_attributes(control, experiment,
                              ['fieldsets', 'advanced_fields'])
     self.assertFalse('redirect' in control.advanced_fields,
                      control.advanced_fields)
     self.assertTrue('redirect' in experiment.advanced_fields,
                     experiment.advanced_fields)
コード例 #9
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_url_overwrite(self):
     with SettingsOverride(CMS_URL_OVERWRITE=False):
         control = AttributeObject()
         contribute_fieldsets(control)
     with SettingsOverride(CMS_URL_OVERWRITE=True):
         experiment = AttributeObject()
         contribute_fieldsets(experiment)
     self.validate_attributes(control, experiment,
                              ['fieldsets', 'advanced_fields'])
     self.assertFalse('overwrite_url' in control.advanced_fields,
                      control.advanced_fields)
     self.assertTrue('overwrite_url' in experiment.advanced_fields,
                     experiment.advanced_fields)
コード例 #10
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_no_cms_enabled_menus(self):
     control = AttributeObject()
     contribute_fieldsets(control)
     old_menus = menu_pool.menus.copy()
     menu_pool.menus = {}
     experiment = AttributeObject()
     contribute_fieldsets(experiment)
     menu_pool.menus = old_menus
     self.validate_attributes(control, experiment,
                              ['fieldsets', 'advanced_fields'])
     self.assertTrue('navigation_extenders' in control.advanced_fields,
                     control.advanced_fields)
     self.assertFalse('navigation_extenders' in experiment.advanced_fields,
                      experiment.advanced_fields)
コード例 #11
0
ファイル: test_frontend.py プロジェクト: bestkatrina/Project
    def _fastlogin(self, **credentials):
        session = import_module(settings.SESSION_ENGINE).SessionStore()
        session.save()
        request = AttributeObject(session=session, META={})
        user = authenticate(**credentials)
        login(request, user)
        session.save()

        # We need to "warm up" the webdriver as we can only set cookies on the
        # current domain
        self.driver.get(self.live_server_url)
        # While we don't care about the page fully loading, Django will freak
        # out if we 'abort' this request, so we wait patiently for it to finish
        self.wait_page_loaded()
        self.driver.add_cookie({
            'name':
            settings.SESSION_COOKIE_NAME,
            'value':
            session.session_key,
            'path':
            '/',
            'domain':
            urlparse(self.live_server_url).hostname
        })
        self.driver.get('{0}/?{1}'.format(
            self.live_server_url, get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')))
        self.wait_page_loaded()
コード例 #12
0
    def test_detail_view_404_when_no_language_is_found(self):
        page = create_page("page1", "nav_playground.html", "en")
        create_title("de", page.get_title(), page, slug=page.get_slug())
        page.publish()

        with SettingsOverride(TEMPLATE_CONTEXT_PROCESSORS=[],
                              CMS_LANGUAGES={
                                  1: [
                                      {
                                          'code': 'x-klingon',
                                          'name': 'Klingon',
                                          'public': True,
                                          'fallbacks': []
                                      },
                                      {
                                          'code': 'x-elvish',
                                          'name': 'Elvish',
                                          'public': True,
                                          'fallbacks': []
                                      },
                                  ]
                              }):
            from cms.views import details
            request = AttributeObject(
                REQUEST={'language': 'x-elvish'},
                GET=[],
                session={},
                path='/',
                current_page=None,
                method='GET',
                COOKIES={},
                META={},
                user=User(),
            )
            self.assertRaises(Http404, details, request, '')
コード例 #13
0
ファイル: test_api.py プロジェクト: bestkatrina/Project
 def test_assign_user_to_page_single(self):
     page = create_page(**self._get_default_create_page_arguments())
     user = get_user_model().objects.create_user(
         username='******', email='*****@*****.**', password='******')
     user.is_staff = True
     user.save()
     request = AttributeObject(user=user)
     assign_user_to_page(page, user, can_change=True)
     self.assertFalse(page.has_change_permission(request))
     self.assertFalse(page.has_add_permission(request))
     _grant_page_permission(user, 'change')
     page = Page.objects.get(pk=page.pk)
     user = get_user_model().objects.get(pk=user.pk)
     request = AttributeObject(user=user)
     self.assertTrue(page.has_change_permission(request))
     self.assertFalse(page.has_add_permission(request))
コード例 #14
0
ファイル: test_api.py プロジェクト: bestkatrina/Project
 def test_assign_user_to_page_nothing(self):
     page = create_page(**self._get_default_create_page_arguments())
     user = get_user_model().objects.create_user(
         username='******', email='*****@*****.**', password='******')
     user.is_staff = True
     request = AttributeObject(user=user)
     self.assertFalse(page.has_change_permission(request))
コード例 #15
0
    def test_detail_view_fallback_language(self):
        '''
        Ask for a page in elvish (doesn't exist), and assert that it fallsback
        to English
        '''
        with SettingsOverride(
                TEMPLATE_CONTEXT_PROCESSORS=[],
                CMS_LANGUAGE_CONF={'x-elvish': [
                    'x-klingon',
                    'en',
                ]},
                CMS_LANGUAGES=[
                    ('x-klingon', 'Klingon'),
                    ('x-elvish', 'Elvish'),
                ]):
            from cms.views import details
            request = AttributeObject(
                REQUEST={'language': 'x-elvish'},
                GET=[],
                session={},
                path='/',
                user=self.test_user,
                current_page=None,
                method='GET',
            )

            response = details(request, '')
            self.assertTrue(isinstance(response, HttpResponseRedirect))
コード例 #16
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/')
コード例 #17
0
 def test_placeholder_name_toolbar(self):
     placeholder_conf_name = 'test_placeholder'
     placeholder_conf_tag = '<div class="cms_placeholder-title">%s</div>' % placeholder_conf_name
     with SettingsOverride(
             CMS_PLACEHOLDER_CONF={'test': {
                 'name': placeholder_conf_name
             }}):
         placeholder = Placeholder()
         placeholder.slot = 'test'
         placeholder.pk = placeholder.id = 99
         context = SekizaiContext()
         context['request'] = AttributeObject(
             REQUEST={'language': 'en'},
             GET=[],
             session={},
             path='/',
             user=self.test_user,
             current_page=None,
             method='GET',
         )
         classes = [
             "cms_placeholder-bar-%s" % placeholder.pk,
             "cms_placeholder_slot::test",
         ]
         output = render_placeholder_toolbar(placeholder, context, '',
                                             'test')
         self.assertTrue(
             placeholder_conf_tag in output,
             'placeholder name %r is not in %r' %
             (placeholder_conf_name, output))
コード例 #18
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
コード例 #19
0
ファイル: multilingual.py プロジェクト: nuaays/Lib
    def test_detail_view_fallback_language(self):
        '''
        Ask for a page in elvish (doesn't exist), and assert that it fallsback
        to English
        '''
        page = create_page("page1", "nav_playground.html", "en")
        with self.settings(
                TEMPLATE_CONTEXT_PROCESSORS=[],
                CMS_LANGUAGES={
                    1: [
                        {
                            'code': 'x-klingon',
                            'name': 'Klingon',
                            'public': True,
                            'fallbacks': []
                        },
                        {
                            'code': 'x-elvish',
                            'name': 'Elvish',
                            'public': True,
                            'fallbacks': [
                                'x-klingon',
                                'en',
                            ]
                        },
                    ]
                },
        ):
            create_title("x-klingon", "futla ak", page, slug=page.get_slug())
            page.publish("x-klingon")
            from cms.views import details

            def get_path():
                return '/'

            def is_secure():
                return False

            def get_host():
                return 'testserver'

            User = get_user_model()
            request = AttributeObject(
                GET=QueryDict('language=x-elvish'),
                POST=QueryDict(''),
                session={},
                path='/',
                current_page=None,
                method='GET',
                COOKIES={},
                META={},
                user=User(),
                get_full_path=get_path,
                is_secure=is_secure,
                get_host=get_host,
            )

            response = details(request, '')
            self.assertTrue(isinstance(response, HttpResponseRedirect))
コード例 #20
0
ファイル: api.py プロジェクト: ppp0/openbroadcast
 def test_assign_user_to_page_all(self):
     page = create_page(**self._get_default_create_page_arguments())
     user = User.objects.create(username='******',
                                email='*****@*****.**',
                                is_staff=True,
                                is_active=True)
     request = AttributeObject(user=user)
     assign_user_to_page(page, user, grant_all=True)
     self.assertFalse(page.has_change_permission(request))
     self.assertTrue(page.has_add_permission(request))
     _grant_page_permission(user, 'change')
     _grant_page_permission(user, 'add')
     page = Page.objects.get(pk=page.pk)
     user = User.objects.get(pk=user.pk)
     request = AttributeObject(user=user)
     self.assertTrue(page.has_change_permission(request))
     self.assertTrue(page.has_add_permission(request))
コード例 #21
0
ファイル: api.py プロジェクト: ppp0/openbroadcast
 def test_assign_user_to_page_nothing(self):
     page = create_page(**self._get_default_create_page_arguments())
     user = User.objects.create(username='******',
                                email='*****@*****.**',
                                is_staff=True,
                                is_active=True)
     request = AttributeObject(user=user)
     self.assertFalse(page.has_change_permission(request))
コード例 #22
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
 def test_dates(self):
     with SettingsOverride(CMS_SHOW_START_DATE=False,
                           CMS_SHOW_END_DATE=False):
         control = AttributeObject()
         contribute_fieldsets(control)
     with SettingsOverride(CMS_SHOW_START_DATE=True,
                           CMS_SHOW_END_DATE=True):
         experiment1 = AttributeObject()
         contribute_fieldsets(experiment1)
     with SettingsOverride(CMS_SHOW_START_DATE=True,
                           CMS_SHOW_END_DATE=False):
         experiment2 = AttributeObject()
         contribute_fieldsets(experiment2)
     with SettingsOverride(CMS_SHOW_START_DATE=False,
                           CMS_SHOW_END_DATE=True):
         experiment3 = AttributeObject()
         contribute_fieldsets(experiment3)
     self.validate_attributes(control, experiment1,
                              ['fieldsets', 'general_fields'])
     self.validate_attributes(control, experiment2,
                              ['fieldsets', 'general_fields'])
     self.validate_attributes(control, experiment3,
                              ['fieldsets', 'general_fields'])
     self.assertFalse(('publication_date', 'publication_end_date')
                      in control.general_fields, control.general_fields)
     self.assertTrue(('publication_date', 'publication_end_date')
                     in experiment1.general_fields,
                     experiment1.general_fields)
     self.assertFalse(('publication_date', 'publication_end_date')
                      in experiment2.general_fields,
                      experiment2.general_fields)
     self.assertFalse(('publication_date', 'publication_end_date')
                      in experiment3.general_fields,
                      experiment3.general_fields)
     self.assertFalse('publication_end_date' in experiment1.general_fields,
                      experiment1.general_fields)
     self.assertFalse('publication_end_date' in experiment2.general_fields,
                      experiment2.general_fields)
     self.assertTrue('publication_end_date' in experiment3.general_fields,
                     experiment3.general_fields)
     self.assertFalse('publication_date' in experiment1.general_fields,
                      experiment1.general_fields)
     self.assertTrue('publication_date' in experiment2.general_fields,
                     experiment2.general_fields)
     self.assertFalse('publication_date' in experiment3.general_fields,
                      experiment3.general_fields)
コード例 #23
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
コード例 #24
0
    def test_detail_view_404_when_no_language_is_found(self):
        page = create_page("page1", "nav_playground.html", "en")
        create_title("de", page.get_title(), page, slug=page.get_slug())
        page.publish('en')
        page.publish('de')

        with self.settings(TEMPLATE_CONTEXT_PROCESSORS=[],
                           CMS_LANGUAGES={
                               1: [
                                   {
                                       'code': 'x-klingon',
                                       'name': 'Klingon',
                                       'public': True,
                                       'fallbacks': []
                                   },
                                   {
                                       'code': 'x-elvish',
                                       'name': 'Elvish',
                                       'public': True,
                                       'fallbacks': []
                                   },
                               ]
                           }):
            from cms.views import details

            def get_path():
                return '/'

            def is_secure():
                return False

            def get_host():
                return 'testserver'

            self.get_request()

            request = AttributeObject(
                GET=QueryDict('language=x-elvish'),
                POST=QueryDict(''),
                session={},
                path='/',
                current_page=None,
                method='GET',
                COOKIES={},
                META={},
                user=AnonymousUser(),
                get_full_path=get_path,
                is_secure=is_secure,
                get_host=get_host,
            )
            self.assertRaises(Http404, details, request, '')
コード例 #25
0
ファイル: admin.py プロジェクト: zhiqunq/django-cms
    def test_no_apphooks(self):
        def func_true(self):
            return True

        def func_false(self):
            return False

        old_get_apphooks = apphook_pool.get_apphooks
        apphook_pool.get_apphooks = MethodType(func_true, apphook_pool,
                                               ApphookPool)
        control = AttributeObject()
        contribute_fieldsets(control)
        apphook_pool.get_apphooks = MethodType(func_false, apphook_pool,
                                               ApphookPool)
        experiment = AttributeObject()
        contribute_fieldsets(experiment)
        self.validate_attributes(control, experiment,
                                 ['fieldsets', 'advanced_fields'])
        self.assertTrue('application_urls' in control.advanced_fields,
                        control.advanced_fields)
        self.assertFalse('application_urls' in experiment.advanced_fields,
                         control.advanced_fields)
        apphook_pool.get_apphooks = old_get_apphooks
コード例 #26
0
    def test_render_placeholder_toolbar(self):
        placeholder = Placeholder()
        placeholder.slot = 'test'
        placeholder.pk = placeholder.id = 99
        request = AttributeObject(
            GET={'language': 'en'},
            session={},
            path='/',
            user=self.test_user,
            current_page=None,
            method='GET',
        )
        request.toolbar = CMSToolbar(request)

        context = SekizaiContext()
        context['request'] = request

        classes = [
            "cms-placeholder-%s" % placeholder.pk,
            'cms-placeholder',
        ]
        output = render_placeholder_toolbar(placeholder, context, 'test', 'en')
        for cls in classes:
            self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
コード例 #27
0
 def test_detail_view_404_when_no_language_is_found(self):
     with SettingsOverride(TEMPLATE_CONTEXT_PROCESSORS=[],
                           CMS_LANGUAGES=[('x-klingon', 'Klingon'),
                                          ('x-elvish', 'Elvish')]):
         from cms.views import details
         request = AttributeObject(
             REQUEST={'language': 'x-elvish'},
             GET=[],
             session={},
             path='/',
             user=self.test_user,
             current_page=None,
             method='GET',
         )
         self.assertRaises(Http404, details, request, '')
コード例 #28
0
    def test_render_placeholder_toolbar(self):
        placeholder = Placeholder()
        placeholder.slot = 'test'
        placeholder.pk = placeholder.id = 99
        request = AttributeObject(
            GET={'language': 'en'},
            session={},
            path='/',
            user=self.test_user,
            current_page=None,
            method='GET',
        )
        request.toolbar = CMSToolbar(request)

        context = SekizaiContext()
        context['request'] = request

        classes = [
            "cms-placeholder-%s" % placeholder.pk,
            'cms-placeholder',
        ]
        output = render_placeholder_toolbar(placeholder, context, 'test', 'en')
        for cls in classes:
            self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
コード例 #29
0
    def test_detail_view_fallback_language(self):
        '''
        Ask for a page in elvish (doesn't exist), and assert that it fallsback
        to English
        '''
        page = create_page("page1", "nav_playground.html", "en")
        with SettingsOverride(
                TEMPLATE_CONTEXT_PROCESSORS=[],
                CMS_LANGUAGES={
                    1: [
                        {
                            'code': 'x-klingon',
                            'name': 'Klingon',
                            'public': True,
                            'fallbacks': []
                        },
                        {
                            'code': 'x-elvish',
                            'name': 'Elvish',
                            'public': True,
                            'fallbacks': [
                                'x-klingon',
                                'en',
                            ]
                        },
                    ]
                },
        ):
            create_title("x-klingon", "futla ak", page, slug=page.get_slug())
            page.publish()
            from cms.views import details

            request = AttributeObject(
                REQUEST={'language': 'x-elvish'},
                GET=[],
                session={},
                path='/',
                current_page=None,
                method='GET',
                COOKIES={},
                META={},
                user=User(),
            )

            response = details(request, '')
            self.assertTrue(isinstance(response, HttpResponseRedirect))
コード例 #30
0
ファイル: middleware.py プロジェクト: yellapuhari1/django-cms
    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
コード例 #31
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)
コード例 #32
0
 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = 'test'
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context['request'] = AttributeObject(
         REQUEST={'language': 'en'},
         GET=[],
         session={},
         path='/',
         user=self.test_user,
         current_page=None,
         method='GET',
     )
     classes = [
         "cms_placeholder-bar-%s" % placeholder.pk,
         "cms_placeholder_slot::test",
     ]
     output = render_placeholder_toolbar(placeholder, context, '', 'test')
     for cls in classes:
         self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
コード例 #33
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