Пример #1
0
class SearchReplaceMixin(object):
    def setUp(self):
        """
        All tests are run against different INSTALLED_APPS
        """
        self.data = Namespace() # namespace all test data
        self.data.template = 'testtemplate.html'
        apps = ['minitrue.testdata', 'django.contrib.admin', 'minitrue',
                'project', 'django.contrib.sessions']
        templates = [(self.data.template, 'testtemplate')]
        self.settings_ctx = SettingsOverride(INSTALLED_APPS=apps,
                                             CMS_TEMPLATES=templates)
        self.settings_ctx.__enter__()
        
        self._populate_database()
    
    def tearDown(self):
        self.settings_ctx.__exit__(None, None, None)
        
    def _populate_database(self):
        """
        Create some test content
        """
        self.data.en_title = "English Title"
        self.data.de_title = "Deutscher Titel"
        self.data.redirect = "/title/redirect/"
        page = create_page(self.data.en_title, self.data.template,
                           'en', redirect=self.data.redirect)
        self.data.en_title_instance = page.title_set.get(language='en')
        self.data.de_title_instance = create_title('de', self.data.de_title, page,
                                                   redirect=self.data.redirect)
    
    def _reload(self, obj):
        return obj.__class__.objects.get(pk=obj.pk)
Пример #2
0
 def setUp(self):
     admin = 'django.contrib.admin'
     noadmin_apps = [
         app for app in settings.INSTALLED_APPS if not app == admin
     ]
     self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
     self._ctx.__enter__()
Пример #3
0
 def test_03_is_media_url(self):
     with SettingsOverride(MEDIA_URL='/media/'):
         request = self.get_request('/media/')
         self.assertTrue(urlutils.is_media_request(request))
         request = self.get_request('/no-media/')
         self.assertFalse(urlutils.is_media_request(request))
     with SettingsOverride(MEDIA_URL='http://testserver2.com/'):
         request = self.get_request('/')
         self.assertFalse(urlutils.is_media_request(request))
     with SettingsOverride(MEDIA_URL='http://testserver/media/'):
         request = self.get_request('/media/')
         self.assertTrue(urlutils.is_media_request(request))
         request = self.get_request('/no-media/')
         self.assertFalse(urlutils.is_media_request(request))
Пример #4
0
    def setUp(self):
        """
        All tests are run against different INSTALLED_APPS
        """
        self.data = Namespace()  # namespace all test data
        self.data.template = 'testtemplate.html'
        apps = [
            'minitrue.testdata', 'django.contrib.admin', 'minitrue', 'project',
            'django.contrib.sessions'
        ]
        templates = [(self.data.template, 'testtemplate')]
        self.settings_ctx = SettingsOverride(INSTALLED_APPS=apps,
                                             CMS_TEMPLATES=templates)
        self.settings_ctx.__enter__()

        self._populate_database()
Пример #5
0
    def test_03_apphook_on_root(self):

        if APP_MODULE in sys.modules:
            del sys.modules[APP_MODULE]

        with SettingsOverride(ROOT_URLCONF='testapp.urls_for_apphook_tests'):
            apphook_pool.clear()
            superuser = User.objects.create_superuser('admin',
                                                      '*****@*****.**',
                                                      'admin')
            page = self.create_page(user=superuser, published=True)
            english_title = page.title_set.all()[0]
            self.assertEquals(english_title.language, 'en')
            Title.objects.create(
                language='de',
                title='%s DE' % english_title.title,
                slug=english_title.slug,
                path=english_title.path,
                page=page,
            )
            page.title_set.all().update(application_urls='SampleApp')
            self.assertTrue(page.publish())

            response = self.client.get(self.get_pages_root())
            self.assertTemplateUsed(response, 'sampleapp/home.html')
            apphook_pool.clear()
Пример #6
0
    def test_11_detail_view_fallsback_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_FALLBACK=True,
                CMS_DBGETTEXT=False,
                CMS_LANGUAGE_CONF={'elvish': [
                    'klingon',
                    'en',
                ]},
                CMS_LANGUAGES=[('klingon', 'Klingon'), ('elvish', 'Elvish')]):
            from cms.views import details

            class Mock:
                pass

            request = Mock()
            setattr(request, 'REQUEST', {'language': 'elvish'})
            setattr(request, 'GET', [])
            setattr(request, 'session', {})
            setattr(request, 'path', '/')
            setattr(request, 'user', self.user)
            setattr(request, 'current_page', None)

            response = details(request, slug=self.test_page.get_slug())
            self.assertTrue(isinstance(response, HttpResponseRedirect))
Пример #7
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
Пример #8
0
class NoAdminPageTests(CMSTestCase):
    urls = 'testapp.noadmin_urls'
    
    def setUp(self):
        admin = 'django.contrib.admin'
        noadmin_apps = [app for app in settings.INSTALLED_APPS if not app == admin]
        self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
        self._ctx.__enter__()
        
    def tearDown(self):
        self._ctx.__exit__(None, None, None)
    
    def test_01_get_page_from_request_fakeadmin_nopage(self):
        request = self.get_request('/admin/')
        page = get_page_from_request(request)
        self.assertEqual(page, None)
Пример #9
0
 def test_14_flat_urls(self):
     with SettingsOverride(CMS_FLAT_URLS=True):
         home_slug = "home"
         child_slug = "child"
         grandchild_slug = "grandchild"
         home = self.create_page(title=home_slug,
                                 published=True,
                                 in_navigation=True)
         home.publish()
         child = self.create_page(parent_page=home,
                                  title=child_slug,
                                  published=True,
                                  in_navigation=True)
         child.publish()
         grandchild = self.create_page(parent_page=child,
                                       title=grandchild_slug,
                                       published=True,
                                       in_navigation=True)
         grandchild.publish()
         response = self.client.get(home.get_absolute_url())
         self.assertEqual(response.status_code, 200)
         response = self.client.get(child.get_absolute_url())
         self.assertEqual(response.status_code, 200)
         response = self.client.get(grandchild.get_absolute_url())
         self.assertEqual(response.status_code, 200)
         self.assertFalse(
             child.get_absolute_url() in grandchild.get_absolute_url())
Пример #10
0
 def test_01_dbgettext_deprecation(self):
     with SettingsOverride(CMS_DBGETTEXT_SLUGS=True):
         self.assertWarns(
             DeprecationWarning,
             "CMS_DBGETTEXT_SLUGS (and general support for django-dbggettext "
             "for CMS contents) will be deprecated in django CMS 2.2.",
             post_patch)
Пример #11
0
 def test_02_show_menu(self):
     with SettingsOverride(CMS_MODERATOR = False):
         context = self.get_context()
         tpl = Template("{% load menu_tags %}{% show_menu %}")
         tpl.render(context) 
         nodes = context['children']
         self.assertEqual(nodes[0].get_absolute_url(), self.get_pages_root())
         self.assertEqual(nodes[0].get_absolute_url(), "/content/")
Пример #12
0
 def setUp(self):
     with SettingsOverride(CMS_MODERATOR = False):
         u = User(username="******", is_staff = True, is_active = True, is_superuser = True)
         u.set_password("test")
         u.save()
         self.login_user(u)
 
         self.create_some_pages()
Пример #13
0
class SettingsOverrideTestCase(CMSTestCase):
    settings_overrides = {}
    
    def _pre_setup(self):
        self._enter_settings_override()
        super(SettingsOverrideTestCase, self)._pre_setup()
        
    def _enter_settings_override(self):
        self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
        self._settings_ctx_manager.__enter__()
        
    def _post_teardown(self):
        super(SettingsOverrideTestCase, self)._post_teardown()
        self._exit_settings_override()
        
    def _exit_settings_override(self):
        self._settings_ctx_manager.__exit__(None, None, None)
Пример #14
0
 def test_03_command_line_should_raise_when_moderator_false(self):
     with SettingsOverride(CMS_MODERATOR=False):
         raised = False
         try:
             com = publisher_publish.Command()
             com.handle_noargs()
         except CommandError:
             raised = True
     self.assertTrue(raised)
Пример #15
0
class NoAdminPageTests(CMSTestCase):
    urls = 'testapp.noadmin_urls'

    def setUp(self):
        admin = 'django.contrib.admin'
        noadmin_apps = [
            app for app in settings.INSTALLED_APPS if not app == admin
        ]
        self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
        self._ctx.__enter__()

    def tearDown(self):
        self._ctx.__exit__(None, None, None)

    def test_01_get_page_from_request_fakeadmin_nopage(self):
        request = self.get_request('/admin/')
        page = get_page_from_request(request)
        self.assertEqual(page, None)
Пример #16
0
 def test_02_language_fallback(self):
     """
     Test language fallbacks in details view
     """
     self.create_page(published=True, language='en')
     request = self.get_request('/', 'de')
     response = details(request, '')
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], '/en/')
     with SettingsOverride(CMS_LANGUAGE_FALLBACK=False):
         self.assertRaises(Http404, details, request, '')
Пример #17
0
 def test_03_show_breadcrumb(self):
     with SettingsOverride(CMS_MODERATOR = False):    
         page2 = Page.objects.get(pk=self.page2.pk)
         context = self.get_context(path=self.page2.get_absolute_url())
         tpl = Template("{% load menu_tags %}{% show_breadcrumb %}")
         tpl.render(context) 
         nodes = context['ancestors']
         self.assertEqual(nodes[0].get_absolute_url(), self.get_pages_root())
         self.assertEqual(nodes[0].get_absolute_url(), "/content/")
         self.assertEqual(isinstance(nodes[0], NavigationNode), True)
         self.assertEqual(nodes[1].get_absolute_url(), page2.get_absolute_url())
Пример #18
0
 def test_05_incorrect_nav_extender_in_db(self):
     with SettingsOverride(CMS_MODERATOR=False):
         self.create_some_nodes()
         page2 = Page.objects.get(pk=self.page2.pk)
         page2.navigation_extenders = "SomethingWrong"
         page2.save()
         context = self.get_context()
         tpl = Template("{% load menu_tags %}{% show_menu %}")
         tpl.render(context)
         nodes = context['children']
         self.assertEqual(len(nodes), 2)
Пример #19
0
 def test_03_extenders_on_root_child(self):
     with SettingsOverride(CMS_MODERATOR=False):
         self.create_some_nodes()
         page4 = Page.objects.get(pk=self.page4.pk)
         page4.navigation_extenders = "TestMenu"
         page4.save()
         context = self.get_context()
         tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
         tpl.render(context)
         nodes = context['children']
         self.assertEqual(len(nodes), 2)
         self.assertEqual(len(nodes[1].children), 4)
Пример #20
0
 def test_00_details_view(self):
     """
     Tests that the `detail` view is working.
     """
     with SettingsOverride(**self.render_settings()):
         from cms.views import details
         response = details(self.get_request(),
                            slug=self.test_page.get_slug())
         r = self.strip_rendered(response.content)
         self.assertEqual(
             r, u'|' + self.test_data['text_main'] + u'|' +
             self.test_data['text_sub'] + u'|')
Пример #21
0
 def test_01_handle_no_page(self):
     """
     Test handle nopage correctly works with DEBUG=True
     """
     request = self.get_request('/')
     slug = ''
     self.assertRaises(Http404, _handle_no_page, request, slug)
     with SettingsOverride(DEBUG=True):
         request = self.get_request('/')
         slug = ''
         response = _handle_no_page(request, slug)
         self.assertEqual(response.status_code, 200)
Пример #22
0
 def test_01_site_framework(self):
     #Test the site framework, and test if it's possible to disable it
     with SettingsOverride(SITE_ID=2):
         page_2a = self.create_page(site=2)
 
         response = self.client.get("/admin/cms/page/?site__exact=3")
         self.assertEqual(response.status_code, 200)
         page_3b = self.create_page(site=3)
         
     with SettingsOverride(SITE_ID=3):
         page_3a = self.create_page(site=3)
         
         # with param
         self.assertEqual(Page.objects.on_site(2).count(), 1)
         self.assertEqual(Page.objects.on_site(3).count(), 2)
         
         self.assertEqual(Page.objects.drafts().on_site().count(), 2)
         
     with SettingsOverride(SITE_ID=2):
         # without param
         self.assertEqual(Page.objects.drafts().on_site().count(), 1)
Пример #23
0
 def setUp(self):
     with SettingsOverride(SITE_ID=1):
         
         u = User(username="******", is_staff = True, is_active = True, is_superuser = True)
         u.set_password("test")
         u.save()
         
         # setup sites
         Site(domain="sample2.com", name="sample2.com").save() # pk 2
         Site(domain="sample3.com", name="sample3.com").save() # pk 3
         
         self.login_user(u)
Пример #24
0
class SearchReplaceMixin(object):
    def setUp(self):
        """
        All tests are run against different INSTALLED_APPS
        """
        self.data = Namespace()  # namespace all test data
        self.data.template = 'testtemplate.html'
        apps = [
            'minitrue.testdata', 'django.contrib.admin', 'minitrue', 'project',
            'django.contrib.sessions'
        ]
        templates = [(self.data.template, 'testtemplate')]
        self.settings_ctx = SettingsOverride(INSTALLED_APPS=apps,
                                             CMS_TEMPLATES=templates)
        self.settings_ctx.__enter__()

        self._populate_database()

    def tearDown(self):
        self.settings_ctx.__exit__(None, None, None)

    def _populate_database(self):
        """
        Create some test content
        """
        self.data.en_title = "English Title"
        self.data.de_title = "Deutscher Titel"
        self.data.redirect = "/title/redirect/"
        page = create_page(self.data.en_title,
                           self.data.template,
                           'en',
                           redirect=self.data.redirect)
        self.data.en_title_instance = page.title_set.get(language='en')
        self.data.de_title_instance = create_title('de',
                                                   self.data.de_title,
                                                   page,
                                                   redirect=self.data.redirect)

    def _reload(self, obj):
        return obj.__class__.objects.get(pk=obj.pk)
Пример #25
0
 def setUp(self):
     """
     All tests are run against different INSTALLED_APPS
     """
     self.data = Namespace() # namespace all test data
     self.data.template = 'testtemplate.html'
     apps = ['minitrue.testdata', 'django.contrib.admin', 'minitrue',
             'project', 'django.contrib.sessions']
     templates = [(self.data.template, 'testtemplate')]
     self.settings_ctx = SettingsOverride(INSTALLED_APPS=apps,
                                          CMS_TEMPLATES=templates)
     self.settings_ctx.__enter__()
     
     self._populate_database()
Пример #26
0
 def test_01_explicit_apphooks(self):
     """
     Test explicit apphook loading with the CMS_APPHOOKS setting.
     """
     if APP_MODULE in sys.modules:
         del sys.modules[APP_MODULE]
     apphooks = ('%s.%s' % (APP_MODULE, APP_NAME), )
     with SettingsOverride(CMS_APPHOOKS=apphooks):
         apphook_pool.clear()
         hooks = apphook_pool.get_apphooks()
         app_names = [hook[0] for hook in hooks]
         self.assertEqual(len(hooks), 1)
         self.assertEqual(app_names, [APP_NAME])
         apphook_pool.clear()
Пример #27
0
 def test_04_get_site_choices_without_moderator(self):
     with SettingsOverride(CMS_MODERATOR=False):
         # boilerplate (creating a page)
         user_super = User(username="******",
                           is_staff=True,
                           is_active=True,
                           is_superuser=True)
         user_super.set_password("super")
         user_super.save()
         self.login_user(user_super)
         self.create_page(title="home", user=user_super)
         # The proper test
         result = get_site_choices()
         self.assertEquals(result, [(1, 'example.com')])
Пример #28
0
 def test_03_apphook_not_hooked(self):
     """
     Test details view when apphook pool has apphooks, but they're not
     actually hooked
     """
     if APP_MODULE in sys.modules:
         del sys.modules[APP_MODULE]
     apphooks = ('%s.%s' % (APP_MODULE, APP_NAME), )
     self.create_page(published=True, language='en')
     with SettingsOverride(CMS_APPHOOKS=apphooks):
         apphook_pool.clear()
         response = self.client.get('/')
         self.assertEqual(response.status_code, 200)
         apphook_pool.clear()
Пример #29
0
 def test_discover2(self):
     """
     Same as test_discover, tests that those tests don't leak 
     """
     _reset(replacer)  # reset against globally INSTALLED_APPS
     with SettingsOverride(INSTALLED_APPS=['minitrue.testdata']):
         _reset(replacer)  # reset against overwritten INSTALLED_APPS
         self.assertFalse(replacer._discovered)
         self.assertEqual(len(replacer.models), 0)
         replacer.discover()
         self.assertTrue(replacer._discovered)
         self.assertEqual(len(replacer.models), 1)
         self.assertTrue(Title in replacer.models)
         self.assertEqual(replacer.models[Title].fields,
                          ['title', 'redirect'])
Пример #30
0
 def test_05_login_required(self):
     self.create_page(
         published=True,
         language='en',
         login_required=True,
     )
     request = self.get_request('/')
     response = details(request, '')
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'], '%s?next=/en/' % settings.LOGIN_URL)
     with SettingsOverride(i18n_installed=False):
         request = self.get_request('/')
         response = details(request, '')
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response['Location'], '%s?next=/' % settings.LOGIN_URL)
Пример #31
0
 def test_discover(self):
     """
     Test automated (explicit) discovery.
     """
     _reset(replacer)  # reset against globally INSTALLED_APPS
     with SettingsOverride(INSTALLED_APPS=['minitrue.testdata']):
         _reset(replacer)  # reset against overwritten INSTALLED_APPS
         self.assertFalse(replacer._discovered)
         self.assertEqual(len(replacer.models), 0)
         replacer.discover()
         self.assertTrue(replacer._discovered)
         self.assertEqual(len(replacer.models), 1)
         self.assertTrue(Title in replacer.models)
         self.assertEqual(replacer.models[Title].fields,
                          ['title', 'redirect'])
Пример #32
0
    def test_02_implicit_apphooks(self):
        """
        Test implicit apphook loading with INSTALLED_APPS + cms_app.py
        """
        if APP_MODULE in sys.modules:
            del sys.modules[APP_MODULE]

        apps = ['testapp.sampleapp']
        with SettingsOverride(INSTALLED_APPS=apps,
                              ROOT_URLCONF='testapp.urls_for_apphook_tests'):
            apphook_pool.clear()
            hooks = apphook_pool.get_apphooks()
            app_names = [hook[0] for hook in hooks]
            self.assertEqual(len(hooks), 1)
            self.assertEqual(app_names, [APP_NAME])
            apphook_pool.clear()
Пример #33
0
 def test_04_extenders_on_child(self):
     with SettingsOverride(CMS_MODERATOR=False):
         self.create_some_nodes()
         page1 = Page.objects.get(pk=self.page1.pk)
         page1.in_navigation = False
         page1.save()
         page2 = Page.objects.get(pk=self.page2.pk)
         page2.navigation_extenders = "TestMenu"
         page2.save()
         context = self.get_context()
         tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
         tpl.render(context)
         nodes = context['children']
         self.assertEqual(len(nodes), 2)
         self.assertEqual(len(nodes[0].children), 4)
         self.assertEqual(nodes[0].children[1].get_absolute_url(), "/")
Пример #34
0
 def setUp(self):
     admin = 'django.contrib.admin'
     noadmin_apps = [app for app in settings.INSTALLED_APPS if not app == admin]
     self._ctx = SettingsOverride(INSTALLED_APPS=noadmin_apps)
     self._ctx.__enter__()
Пример #35
0
 def _enter_settings_override(self):
     self._settings_ctx_manager = SettingsOverride(
         **self.settings_overrides)
     self._settings_ctx_manager.__enter__()