Ejemplo n.º 1
0
 def test_page_id_in_template(self):
     """Get a page in the templates via the page id."""
     page = self.create_new_page()
     request = get_request_mock()
     temp = loader.get_template('pages/tests/test4.html')
     render = temp.render({})
     self.assertTrue(page.title() in render)
Ejemplo n.º 2
0
    def test_redirect_old_slug(self):
        """Test that a page redirect to new slug."""
        c = self.get_admin_client()
        c.login(username='******', password='******')
        page_data = self.get_new_page_data()
        page_data['slug'] = 'page1'
        response = c.post(reverse('admin:pages_page_add'), page_data)
        self.assertRedirects(response, '/admin/pages/page/')
        page = Page.objects.all()[0]
        page_data['slug'] = 'page2'
        response = c.post(reverse("admin:pages_page_change", args=[page.id]),
                          page_data)
        self.assertRedirects(response, '/admin/pages/page/')
        page = Page.objects.get(id=page.id)
        self.assertEqual(page.slug(), 'page2')

        req = get_request_mock()

        def _get_context_page(path):
            return details(req, path, 'en-us')

        self.assertEqual(_get_context_page('/pages/page1/').status_code, 200)

        # Activate redirect
        self.set_setting("PAGE_REDIRECT_OLD_SLUG", True)
        self.assertEqual(_get_context_page('/pages/page1/').status_code, 301)
        self.assertEqual(
            _get_context_page('/pages/page1/')._headers['location'][1],
            '/pages/page2')
Ejemplo n.º 3
0
    def test_redirect_old_slug(self):
        """Test that a page redirect to new slug."""
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['slug'] = 'page1'
        response = c.post(reverse('admin:pages_page_add'), page_data)
        self.assertRedirects(response, changelist_url)
        page = Page.objects.all()[0]
        page_data['slug'] = 'page2'
        response = c.post(reverse("admin:pages_page_change", args=[page.id]), page_data)
        self.assertRedirects(response, changelist_url)
        page = Page.objects.get(id=page.id)
        self.assertEqual(page.slug(), 'page2')

        req = get_request_mock()

        def _get_context_page(path):
            return details(req, path, 'en-us')

        self.assertEqual(_get_context_page('/pages/page1/').status_code, 200)

        # Activate redirect
        self.set_setting("PAGE_REDIRECT_OLD_SLUG", True)
        self.assertEqual(_get_context_page('/pages/page1/').status_code, 301)
        self.assertEqual(_get_context_page('/pages/page1/')._headers['location'][1], '/pages/page2')
Ejemplo n.º 4
0
    def test_pages_edit_init(self):
        """Test initializing page edit"""
        tpl = "{% load pages_tags %}{% pages_edit_init %}"
        user = User.objects.create_user(username='******',
                                        email='*****@*****.**',
                                        password='******')
        request = get_request_mock()
        request.user = user

        template = self.get_template_from_string(tpl)

        # Test accessing by non-staff user
        self.assertEqual(
            render(template, context=Context({'request': request})), '')

        request.user.is_staff = True
        # Test not using the tag on a cms page
        self.assertEqual(
            render(template,
                   context=Context({
                       'request': request,
                       'template_name': 'foo.html'
                   })), '')

        # Test regular
        page = self.new_page({'slug': 'page1'})
        self.assertNotEqual(
            render(template,
                   context=Context({
                       'request': request,
                       'template_name': 'pages/examples/cool.html',
                       'current_page': page
                   })), '')
Ejemplo n.º 5
0
    def test_default_view_with_language_prefix(self):
        """
        Test that everything is working with the language prefix option
        activated.
        """
        self.set_setting("PAGE_USE_LANGUAGE_PREFIX", True)

        from pages.views import details
        req = get_request_mock()
        self.assertRaises(Http404, details, req, '/pages/')

        page1 = self.new_page(content={'slug': 'page1'})
        page2 = self.new_page(content={'slug': 'page2'})

        self.assertEqual(page1.get_url_path(),
            reverse('pages-details-by-path', args=[],
            kwargs={'lang': 'en-us', 'path': 'page1'})
        )

        self.assertEqual(details(req, page1.get_url_path(),
            only_context=True)['current_page'],
            page1)

        self.assertEqual(details(req, path=page2.get_complete_slug(),
            only_context=True)['current_page'], page2)

        self.assertEqual(details(req, page2.get_url_path(),
            only_context=True)['current_page'],
            page2)

        self.set_setting("PAGE_USE_LANGUAGE_PREFIX", False)

        self.assertEqual(details(req, page2.get_url_path(),
            only_context=True)['current_page'],
            page2)
Ejemplo n.º 6
0
 def test_page_id_in_template(self):
     """Get a page in the templates via the page id."""
     page = self.create_new_page()
     request = get_request_mock()
     temp = loader.get_template('pages/tests/test4.html')
     render = temp.render({})
     self.assertTrue(page.title() in render)
Ejemplo n.º 7
0
    def test_default_view_with_language_prefix(self):
        """
        Test that everything is working with the language prefix option
        activated.
        """
        self.set_setting("PAGE_USE_LANGUAGE_PREFIX", True)

        from pages.views import details
        req = get_request_mock()
        self.assertRaises(Http404, details, req, '/pages/')

        page1 = self.new_page(content={'slug': 'page1'})
        page2 = self.new_page(content={'slug': 'page2'})

        self.assertEqual(page1.get_url_path(),
            reverse('pages-details-by-path', args=[],
            kwargs={'lang': 'en', 'path': 'page1'})
        )

        self.assertEqual(details(req, page1.get_url_path(),
            only_context=True)['current_page'],
            page1)

        self.assertEqual(details(req, path=page2.get_complete_slug(),
            only_context=True)['current_page'], page2)

        self.assertEqual(details(req, page2.get_url_path(),
            only_context=True)['current_page'],
            page2)

        self.set_setting("PAGE_USE_LANGUAGE_PREFIX", False)

        self.assertEqual(details(req, page2.get_url_path(),
            only_context=True)['current_page'],
            page2)
Ejemplo n.º 8
0
 def test_context_processor(self):
     """Test that the page's context processor is properly activated."""
     from pages.views import details
     req = get_request_mock()
     page1 = self.new_page(content={'slug': 'page1', 'title': 'hello', 'status': 'published'})
     page1.save()
     self.set_setting("PAGES_STATIC_URL", "test_request_context")
     self.assertContains(details(req, path='/'), "test_request_context")
Ejemplo n.º 9
0
 def test_context_processor(self):
     """Test that the page's context processor is properly activated."""
     from pages.views import details
     req = get_request_mock()
     page1 = self.new_page(content={'slug': 'page1', 'title': 'hello'})
     page1.save()
     self.set_setting("PAGES_MEDIA_URL", "test_request_context")
     self.assertContains(details(req, path='/'), "test_request_context")
Ejemplo n.º 10
0
    def test_block_placeholder(self):
        """Test block rendering."""

        template = django.template.loader.get_template('block_placeholder.html')

        page = self.new_page({"block_1": "content", "block_2": "content"})
        context = {'current_page': page, 'request': get_request_mock()}
        self.assertTrue("block 1:content;" in render(template, context), render(template, context))
        self.assertTrue("block 2:content;" in render(template, context), render(template, context))
Ejemplo n.º 11
0
    def test_block_placeholder(self):
        """Test block rendering."""

        template = django.template.loader.get_template(
            'block_placeholder.html')

        page = self.new_page({"block_1": "content", "block_2": "content"})
        context = {'current_page': page, 'request': get_request_mock()}
        self.assertTrue("block 1:content;" in render(template, context),
                        render(template, context))
        self.assertTrue("block 2:content;" in render(template, context),
                        render(template, context))
Ejemplo n.º 12
0
    def test_urls_in_templates(self):
        """Test different ways of displaying urls in templates."""
        page = self.create_new_page()
        request = get_request_mock()
        temp = loader.get_template('pages/tests/test7.html')
        temp = loader.get_template('pages/tests/test6.html')
        render = temp.render({'current_page': page})

        self.assertTrue('t1_' + page.get_url_path() in render)
        self.assertTrue('t2_' + page.get_url_path() in render)
        self.assertTrue('t3_' + page.get_url_path() in render)
        self.assertTrue('t4_' + page.slug() in render)
        self.assertTrue('t5_' + page.slug() in render)
Ejemplo n.º 13
0
 def test_bug_162(self):
     """Test bug 162
     http://code.google.com/p/django-page-cms/issues/detail?id=162"""
     c = self.get_admin_client()
     page_data = self.get_new_page_data()
     page_data['title'] = 'test-162-title'
     page_data['slug'] = 'test-162-slug'
     response = c.post(add_url, page_data)
     self.assertRedirects(response, reverse("admin:pages_page_changelist"))
     request = get_request_mock()
     temp = loader.get_template('pages/tests/test2.html')
     render = temp.render({})
     self.assertTrue('test-162-slug' in render)
Ejemplo n.º 14
0
 def test_bug_162(self):
     """Test bug 162
     http://code.google.com/p/django-page-cms/issues/detail?id=162"""
     c = self.get_admin_client()
     page_data = self.get_new_page_data()
     page_data['title'] = 'test-162-title'
     page_data['slug'] = 'test-162-slug'
     response = c.post(add_url, page_data)
     self.assertRedirects(response, reverse("admin:pages_page_changelist"))
     request = get_request_mock()
     temp = loader.get_template('pages/tests/test2.html')
     render = temp.render({})
     self.assertTrue('test-162-slug' in render)
Ejemplo n.º 15
0
    def test_urls_in_templates(self):
        """Test different ways of displaying urls in templates."""
        page = self.create_new_page()
        request = get_request_mock()
        temp = loader.get_template('pages/tests/test7.html')
        temp = loader.get_template('pages/tests/test6.html')
        render = temp.render({'current_page':page})

        self.assertTrue('t1_'+page.get_url_path() in render)
        self.assertTrue('t2_'+page.get_url_path() in render)
        self.assertTrue('t3_'+page.get_url_path() in render)
        self.assertTrue('t4_'+page.slug() in render)
        self.assertTrue('t5_'+page.slug() in render)
Ejemplo n.º 16
0
 def test_bug_162(self):
     """Test bug 162
     http://code.google.com/p/django-page-cms/issues/detail?id=162"""
     c = self.get_admin_client()
     c.login(username= '******', password='******')
     page_data = self.get_new_page_data()
     page_data['title'] = 'test-162-title'
     page_data['slug'] = 'test-162-slug'
     response = c.post('/admin/pages/page/add/', page_data)
     self.assertRedirects(response, '/admin/pages/page/')
     request = get_request_mock()
     temp = loader.get_template('pages/tests/test2.html')
     render = temp.render({})
     self.assertTrue('test-162-slug' in render)
Ejemplo n.º 17
0
    def test_placeholder_section(self):
        tpl = ("{% load pages_tags %}{% placeholder 'meta_description' section 'SEO Options' %}")

        template = self.get_template_from_string(tpl)
        found = False
        for node in template.nodelist:
            if isinstance(node, PlaceholderNode):
                found = True
                self.assertEqual(node.section, 'SEO Options')
        self.assertTrue(found)

        page = self.new_page({'meta_description': 'foo'})
        context = {'current_page': page, 'request': get_request_mock()}
        self.assertTrue("foo" in render(template, context))
Ejemplo n.º 18
0
    def test_placeholder_section(self):
        tpl = ("{% load pages_tags %}{% placeholder 'meta_description' section 'SEO Options' %}")

        template = self.get_template_from_string(tpl)
        found = False
        for node in template.nodelist:
            if isinstance(node, PlaceholderNode):
                found = True
                self.assertEqual(node.section, 'SEO Options')
        self.assertTrue(found)

        page = self.new_page({'meta_description': 'foo'})
        context = {'current_page': page, 'request': get_request_mock()}
        self.assertTrue("foo" in render(template, context))
Ejemplo n.º 19
0
    def test_view_context(self):
        """
        Test that the default view can only return the context
        """
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['slug'] = 'page1'
        # create a page for the example otherwise you will get a Http404 error
        response = c.post(add_url, page_data)
        page1 = Content.objects.get_content_slug_by_slug('page1').page

        from pages.views import details
        request = get_request_mock()
        context = details(request, path='/page1/', only_context=True)
        self.assertEqual(context['current_page'], page1)
Ejemplo n.º 20
0
    def test_view_context(self):
        """
        Test that the default view can only return the context
        """
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['slug'] = 'page1'
        # create a page for the example otherwise you will get a Http404 error
        response = c.post(add_url, page_data)
        page1 = Content.objects.get_content_slug_by_slug('page1').page

        from pages.views import details
        request = get_request_mock()
        context = details(request, path='/page1/', only_context=True)
        self.assertEqual(context['current_page'], page1)
Ejemplo n.º 21
0
    def test_bug_172(self):
        """Test bug 167
        http://code.google.com/p/django-page-cms/issues/detail?id=172"""
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['title'] = 'title-en-us'
        page_data['slug'] = 'slug'
        response = c.post(add_url, page_data)
        page = Content.objects.get_content_slug_by_slug('slug').page
        Content(page=page, type='title', language='fr-ch',
                body="title-fr-ch").save()

        request = get_request_mock()
        temp = loader.get_template('pages/tests/test3.html')
        render = temp.render({'page': page})
        self.assertTrue('title-en-us' in render)

        render = temp.render({'page': page, 'lang': 'fr-ch'})
        self.assertTrue('title-fr-ch' in render)
Ejemplo n.º 22
0
    def test_bug_172(self):
        """Test bug 167
        http://code.google.com/p/django-page-cms/issues/detail?id=172"""
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['title'] = 'title-en-us'
        page_data['slug'] = 'slug'
        response = c.post(add_url, page_data)
        page = Content.objects.get_content_slug_by_slug('slug').page
        Content(page=page, type='title', language='fr',
            body="title-fr-ch").save()

        request = get_request_mock()
        temp = loader.get_template('pages/tests/test3.html')
        render = temp.render({'page':page})
        self.assertTrue('title-en-us' in render)

        render = temp.render({'page':page, 'lang':'fr'})
        self.assertTrue('title-fr-ch' in render)
Ejemplo n.º 23
0
    def test_contact_placeholder(self):
        tpl = ("{% load pages_tags %}{% contactplaceholder contact %}")

        template = self.get_template_from_string(tpl)
        page = self.new_page({'contact': 'hello'})
        context = {'current_page': page}

        import logging
        logger = logging.getLogger("pages")
        lvl = logger.getEffectiveLevel()
        logger.setLevel(logging.ERROR)

        with self.assertRaises(ValueError):
            self.assertEqual(render(template, context), 'hello')

        logger.setLevel(lvl)

        context = {'current_page': page, 'request': get_request_mock()}
        self.assertTrue("<form" in render(template, context))
Ejemplo n.º 24
0
    def test_contact_placeholder(self):
        tpl = ("{% load pages_tags %}{% contactplaceholder contact %}")

        template = self.get_template_from_string(tpl)
        page = self.new_page({'contact': 'hello'})
        context = {'current_page': page}

        import logging
        logger = logging.getLogger("pages")
        lvl = logger.getEffectiveLevel()
        logger.setLevel(logging.ERROR)

        with self.assertRaises(ValueError):
            self.assertEqual(render(template, context), 'hello')

        logger.setLevel(lvl)

        context = {'current_page': page, 'request': get_request_mock()}
        self.assertTrue("<form" in render(template, context))
Ejemplo n.º 25
0
    def test_contact_placeholder(self):
        tpl = "{% load pages_tags %}{% contactplaceholder contact %}"

        template = self.get_template_from_string(tpl)
        page = self.new_page({"contact": "hello"})
        context = Context({"current_page": page})

        import logging

        logger = logging.getLogger("pages")
        lvl = logger.getEffectiveLevel()
        logger.setLevel(logging.ERROR)

        with self.assertRaises(ValueError):
            self.assertEqual(template.render(context), "hello")

        logger.setLevel(lvl)

        context = Context({"current_page": page, "request": get_request_mock()})
        self.assertTrue("<form" in template.render(context))
Ejemplo n.º 26
0
    def test_path_too_long(self):
        """Test that the CMS try to resolve the whole page path to find
        a suitable sub path with delegation."""
        page1 = self.new_page(content={'slug': 'page1'})
        page2 = self.new_page(content={'slug': 'page2'})
        from pages import urlconf_registry as reg
        reg.register_urlconf('test2',
                             'pages.testproj.documents.urls',
                             label='test')
        page2.delegate_to = 'test2'
        page1.delegate_to = 'test2'
        page1.save()
        page2.save()
        page2.parent = page1
        page2.save()

        from pages.testproj.documents.models import Document
        doc = Document(title='doc title 1', text='text', page=page1)
        doc.save()

        req = get_request_mock()
        self.set_setting("PAGE_HIDE_ROOT_SLUG", False)
        page1.invalidate()
        page2.invalidate()

        def _get_context_page(path):
            return details(req, path, 'en-us')

        self.assertEqual(_get_context_page('/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2/').status_code, 200)
        self.assertEqual(
            _get_context_page('/page1/page2/doc-%d' % doc.id).status_code, 200)
        self.assertRaises(Http404, _get_context_page,
                          '/page1/page-wrong/doc-%d' % doc.id)

        reg.registry = []
Ejemplo n.º 27
0
    def test_pages_edit_init(self):
        """Test initializing page edit"""
        tpl = "{% load pages_tags %}{% pages_edit_init %}"
        user = User.objects.create_user(username='******', email='*****@*****.**', password='******')
        request = get_request_mock()
        request.user = user

        template = self.get_template_from_string(tpl)

        # Test accessing by non-staff user
        self.assertEqual(render(template, context=Context({'request': request})), '')

        request.user.is_staff = True
        # Test not using the tag on a cms page
        self.assertEqual(render(template, context=Context({
            'request': request, 'template_name': 'foo.html'
        })), '')

        # Test regular
        page = self.new_page({'slug': 'page1'})
        self.assertNotEqual(render(template, context=Context({
            'request': request, 'template_name': 'pages/examples/cool.html', 'current_page': page
        })), '')
Ejemplo n.º 28
0
    def test_path_too_long(self):
        """Test that the CMS try to resolve the whole page path to find
        a suitable sub path with delegation."""
        page1 = self.new_page(content={"slug": "page1"})
        page2 = self.new_page(content={"slug": "page2"})
        from pages import urlconf_registry as reg

        reg.register_urlconf("test2", "pages.testproj.documents.urls", label="test")
        page2.delegate_to = "test2"
        page1.delegate_to = "test2"
        page1.save()
        page2.save()
        page2.parent = page1
        page2.save()

        from pages.testproj.documents.models import Document

        doc = Document(title="doc title 1", text="text", page=page1)
        doc.save()

        req = get_request_mock()
        self.set_setting("PAGE_HIDE_ROOT_SLUG", False)
        page1.invalidate()
        page2.invalidate()

        def _get_context_page(path):
            return details(req, path, "en-us")

        self.assertEqual(_get_context_page("/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/page2").status_code, 200)
        self.assertEqual(_get_context_page("/page1/page2/").status_code, 200)
        self.assertEqual(_get_context_page("/page1/page2/doc-%d" % doc.id).status_code, 200)
        self.assertRaises(Http404, _get_context_page, "/page1/page-wrong/doc-%d" % doc.id)

        reg.registry = []
Ejemplo n.º 29
0
    def test_path_too_long(self):
        """Test that the CMS try to resolve the whole page path to find
        a suitable sub path with delegation."""
        page1 = self.new_page(content={'slug':'page1'})
        page2 = self.new_page(content={'slug':'page2'})
        from pages import urlconf_registry as reg
        reg.register_urlconf('test2', 'pages.testproj.documents.urls',
            label='test')
        page2.delegate_to = 'test2'
        page1.delegate_to = 'test2'
        page1.save()
        page2.save()
        page2.parent = page1
        page2.save()

        from pages.testproj.documents.models import Document
        doc = Document(title='doc title 1', text='text', page=page1)
        doc.save()

        req = get_request_mock()
        self.set_setting("PAGE_HIDE_ROOT_SLUG", False)
        page1.invalidate()
        page2.invalidate()

        def _get_context_page(path):
            return details(req, path, 'en-us')
        self.assertEqual(_get_context_page('/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2/').status_code, 200)
        self.assertEqual(_get_context_page('/page1/page2/doc-%d' % doc.id
            ).status_code, 200)
        self.assertRaises(Http404, _get_context_page,
            '/page1/page-wrong/doc-%d' % doc.id)

        reg.registry = []
Ejemplo n.º 30
0
 def test_bug_178(self):
     """http://code.google.com/p/django-page-cms/issues/detail?id=178"""
     request = get_request_mock()
     temp = loader.get_template('pages/tests/test5.html')
     render = temp.render({'page':None})
Ejemplo n.º 31
0
 def test_bug_178(self):
     """http://code.google.com/p/django-page-cms/issues/detail?id=178"""
     request = get_request_mock()
     temp = loader.get_template('pages/tests/test5.html')
     render = temp.render({'page': None})
Ejemplo n.º 32
0
 def test_request_mockup(self):
     request = get_request_mock()
     self.assertEqual(hasattr(request, 'session'), True)
Ejemplo n.º 33
0
 def test_request_mockup(self):
     request = get_request_mock()
     self.assertEqual(hasattr(request, 'session'), True)