Exemple #1
0
 def test_zinnia_entry_archive_year(self):
     setup_test_template_loader(
         {'zinnia/archives/2010/entry_archive_year.html': ''})
     response = self.check_publishing_context('/2010/', 2, 3, 'entry_list')
     self.assertTemplateUsed(
         response, 'zinnia/archives/2010/entry_archive_year.html')
     restore_template_loaders()
Exemple #2
0
 def test_zinnia_entry_detail_login_password(self):
     setup_test_template_loader(
         {'zinnia/entry_detail.html': '',
          'zinnia/login.html': '',
          'zinnia/password.html': ''})
     entry = self.create_published_entry()
     entry.password = '******'
     entry.login_required = True
     entry.save()
     with self.assertNumQueries(4):
         response = self.client.get('/2010/01/01/my-test-entry/')
     self.assertTemplateUsed(response, 'zinnia/login.html')
     with self.assertNumQueries(11):
         response = self.client.post('/2010/01/01/my-test-entry/',
                                     {'username': '******',
                                      'password': '******'})
     self.assertEquals(response.status_code, 200)
     self.assertTemplateUsed(response, 'zinnia/password.html')
     self.assertEquals(response.context['error'], False)
     with self.assertNumQueries(6):
         response = self.client.post('/2010/01/01/my-test-entry/',
                                     {'entry_password': '******'})
     self.assertEquals(response.status_code, 200)
     self.assertTemplateUsed(response, 'zinnia/entry_detail.html')
     restore_template_loaders()
 def test_zinnia_trackback(self):
     setup_test_template_loader({"404.html": ""})
     response = self.client.post("/trackback/404/")
     self.assertEquals(response.status_code, 404)
     restore_template_loaders()
     self.assertEquals(self.client.post("/trackback/1/").status_code, 301)
     self.assertEquals(self.client.get("/trackback/1/").status_code, 301)
     entry = Entry.objects.get(slug="test-1")
     entry.pingback_enabled = False
     entry.save()
     self.assertEquals(
         self.client.post("/trackback/1/", {"url": "http://example.com"}).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         "<error>1</error>\n  <message>Trackback is not enabled for "
         "Test 1</message>\n  \n</response>\n",
     )
     entry.pingback_enabled = True
     entry.save()
     with self.assertNumQueries(4):
         self.assertEquals(
             self.client.post("/trackback/1/", {"url": "http://example.com"}).content,
             '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  ' "<error>0</error>\n  \n</response>\n",
         )
     self.assertEquals(
         self.client.post("/trackback/1/", {"url": "http://example.com"}).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         "<error>1</error>\n  <message>Trackback is already registered"
         "</message>\n  \n</response>\n",
     )
Exemple #4
0
    def test_comment_success(self):
        setup_test_template_loader(
            {'comments/zinnia/entry/posted.html': '',
             'zinnia/entry_list.html': ''})
        with self.assertNumQueries(0):
            response = self.client.get('/comments/success/')
        self.assertTemplateUsed(response, 'comments/zinnia/entry/posted.html')
        self.assertEquals(response.context['comment'], None)

        with self.assertNumQueries(1):
            response = self.client.get('/comments/success/?c=42')
        self.assertEquals(response.context['comment'], None)

        comment = comments.get_model().objects.create(
            comment='My Comment 1', content_object=self.category,
            site=self.site, is_public=False)
        with self.assertNumQueries(1):
            response = self.client.get('/comments/success/?c=1')
        self.assertEquals(response.context['comment'], comment)
        comment.is_public = True
        comment.save()
        with self.assertNumQueries(5):
            response = self.client.get('/comments/success/?c=1', follow=True)
        self.assertEquals(
            response.redirect_chain[1],
            ('http://example.com/categories/tests/', 302))
        restore_template_loaders()
    def test_comment_success(self):
        with self.assertNumQueries(0):
            response = self.client.get("/comments/success/")
        self.assertTemplateUsed(response, "comments/zinnia/entry/posted.html")
        self.assertEquals(response.context["comment"], None)

        with self.assertNumQueries(1):
            response = self.client.get("/comments/success/?c=42")
        self.assertEquals(response.context["comment"], None)

        comment = comments.get_model().objects.create(
            comment="My Comment 1", content_object=self.category, site=self.site, is_public=False
        )
        setup_test_template_loader({"comments/zinnia/entry/posted.html": "", "zinnia/entry_list.html": ""})
        with self.assertNumQueries(1):
            response = self.client.get("/comments/success/?c=1")
        self.assertEquals(response.context["comment"], comment)
        comment.is_public = True
        comment.save()
        with self.assertNumQueries(5):
            response = self.client.get("/comments/success/?c=1", follow=True)
        self.assertEquals(
            response.redirect_chain,
            [("http://testserver/comments/cr/13/1/#comment-1-by-", 301), ("http://example.com/categories/tests/", 302)],
        )
        restore_template_loaders()
 def test_zinnia_category_list(self):
     setup_test_template_loader({"zinnia/category_list.html": ""})
     self.check_publishing_context("/categories/", 1, friendly_context="category_list", queries=0)
     entry = Entry.objects.all()[0]
     entry.categories.add(Category.objects.create(title="New category", slug="new-category"))
     self.check_publishing_context("/categories/", 2)
     restore_template_loaders()
 def test_zinnia_trackback(self):
     setup_test_template_loader(
         {'404.html': ''})
     response = self.client.post('/trackback/404/')
     self.assertEquals(response.status_code, 404)
     restore_template_loaders()
     self.assertEquals(
         self.client.post('/trackback/1/').status_code, 301)
     self.assertEquals(
         self.client.get('/trackback/1/').status_code, 301)
     entry = Entry.objects.get(slug='test-1')
     entry.pingback_enabled = False
     entry.save()
     self.assertEquals(
         self.client.post('/trackback/1/',
                          {'url': 'http://example.com'}).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         '<error>1</error>\n  <message>Trackback is not enabled for '
         'Test 1</message>\n  \n</response>\n')
     entry.pingback_enabled = True
     entry.save()
     with self.assertNumQueries(5):
         self.assertEquals(
             self.client.post('/trackback/1/',
                              {'url': 'http://example.com'}).content,
             '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
             '<error>0</error>\n  \n</response>\n')
     self.assertEquals(
         self.client.post('/trackback/1/',
                          {'url': 'http://example.com'}).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         '<error>1</error>\n  <message>Trackback is already registered'
         '</message>\n  \n</response>\n')
 def test_zinnia_trackback(self):
     setup_test_template_loader({"404.html": ""})
     response = self.client.post("/trackback/404/")
     self.assertEquals(response.status_code, 404)
     restore_template_loaders()
     self.assertEquals(self.client.post("/trackback/1/").status_code, 301)
     self.assertEquals(self.client.get("/trackback/1/").status_code, 301)
     entry = Entry.objects.get(slug="test-1")
     self.assertEquals(entry.trackback_count, 0)
     entry.trackback_enabled = False
     entry.save()
     self.assertEquals(
         self.client.post("/trackback/1/", {"url": "http://example.com"}).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         "<error>1</error>\n  <message>Trackback is not enabled for "
         "Test 1</message>\n  \n</response>\n",
     )
     entry.trackback_enabled = True
     entry.save()
     connect_discussion_signals()
     get_user_flagger()  # Memoize user flagger for stable query number
     with self.assertNumQueries(6):
         self.assertEquals(
             self.client.post("/trackback/1/", {"url": "http://example.com"}).content,
             '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  ' "<error>0</error>\n  \n</response>\n",
         )
     disconnect_discussion_signals()
     entry = Entry.objects.get(pk=entry.pk)
     self.assertEquals(entry.trackback_count, 1)
     self.assertEquals(
         self.client.post("/trackback/1/", {"url": "http://example.com"}).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         "<error>1</error>\n  <message>Trackback is already registered"
         "</message>\n  \n</response>\n",
     )
Exemple #9
0
 def test_403_template(self):
     # Set up a test 403.html template.
     setup_test_template_loader({"403.html": "This is a test template for a 403 Forbidden error."})
     try:
         response = self.client.get("/views/raises403/")
         self.assertContains(response, "test template", status_code=403)
     finally:
         restore_template_loaders()
Exemple #10
0
 def test_zinnia_entry_archive_index(self):
     template_name_today = 'zinnia/archives/%s/entry_archive.html' % \
                           date.today().strftime('%Y/%m/%d')
     setup_test_template_loader(
         {template_name_today: ''})
     response = self.check_publishing_context('/', 2, 3, 'entry_list')
     self.assertTemplateUsed(response, template_name_today)
     restore_template_loaders()
 def test_zinnia_tag_detail(self):
     setup_test_template_loader({"zinnia/tag/tests/entry_list.html": "", "404.html": ""})
     response = self.check_publishing_context("/tags/tests/", 2, 3, "entry_list", 2)
     self.assertTemplateUsed(response, "zinnia/tag/tests/entry_list.html")
     self.assertEquals(response.context["tag"].name, "tests")
     response = self.client.get("/tags/404/")
     self.assertEquals(response.status_code, 404)
     restore_template_loaders()
 def test_zinnia_tag_list(self):
     setup_test_template_loader({"zinnia/tag_list.html": ""})
     self.check_publishing_context("/tags/", 1, friendly_context="tag_list", queries=1)
     entry = Entry.objects.all()[0]
     entry.tags = "tests, tag"
     entry.save()
     self.check_publishing_context("/tags/", 2)
     restore_template_loaders()
Exemple #13
0
 def test_403(self):
     # Ensure no 403.html template exists to test the default case.
     setup_test_template_loader({})
     try:
         response = self.client.get('/views/raises403/')
         self.assertContains(response, '<h1>403 Forbidden</h1>', status_code=403)
     finally:
         restore_template_loaders()
Exemple #14
0
 def tearDown(self):
     """Always try to restore the initial template loaders
     even if the test_template_loader has not been enabled,
     to avoid cascading errors if a test fails"""
     try:
         restore_template_loaders()
     except AttributeError:
         pass
Exemple #15
0
 def test_zinnia_entry_random(self):
     setup_test_template_loader(
         {'zinnia/entry_detail.html': ''})
     response = self.client.get('/random/', follow=True)
     self.assertTrue(response.redirect_chain[0][0].startswith(
         'http://testserver/2010/'))
     self.assertEquals(response.redirect_chain[0][1], 302)
     restore_template_loaders()
 def test_zinnia_entry_archive_week(self):
     setup_test_template_loader({"zinnia/archives/2010/week/00/entry_archive_week.html": ""})
     response = self.check_publishing_context("/2010/week/00/", 1, 2, "entry_list", 1)
     self.assertTemplateUsed(response, "zinnia/archives/2010/week/00/entry_archive_week.html")
     # All days in a new year preceding the first Monday
     # are considered to be in week 0.
     self.assertEquals(response.context["week"], date(2009, 12, 28))
     self.assertEquals(response.context["week_end_day"], date(2010, 1, 3))
     restore_template_loaders()
Exemple #17
0
 def test_zinnia_category_detail(self):
     setup_test_template_loader(
         {'zinnia/category/tests/entry_list.html': ''})
     response = self.check_publishing_context(
         '/categories/tests/', 2, 3, 'entry_list', 2)
     self.assertTemplateUsed(
         response, 'zinnia/category/tests/entry_list.html')
     self.assertEquals(response.context['category'].slug, 'tests')
     restore_template_loaders()
 def test_zinnia_author_list(self):
     setup_test_template_loader({"zinnia/author_list.html": ""})
     self.check_publishing_context("/authors/", 1, friendly_context="author_list", queries=0)
     user = Author.objects.create(username="******", email="*****@*****.**")
     self.check_publishing_context("/authors/", 1)
     entry = Entry.objects.all()[0]
     entry.authors.add(user)
     self.check_publishing_context("/authors/", 2)
     restore_template_loaders()
Exemple #19
0
 def test_zinnia_author_detail(self):
     setup_test_template_loader(
         {'zinnia/author/admin/entry_list.html': ''})
     response = self.check_publishing_context(
         '/authors/admin/', 2, 3, 'entry_list', 2)
     self.assertTemplateUsed(
         response, 'zinnia/author/admin/entry_list.html')
     self.assertEquals(response.context['author'].username, 'admin')
     restore_template_loaders()
 def test_zinnia_entry_search(self):
     setup_test_template_loader({"zinnia/entry_search.html": ""})
     self.check_publishing_context("/search/?pattern=test", 2, 3, "entry_list", 1)
     response = self.client.get("/search/?pattern=ab")
     self.assertEquals(len(response.context["object_list"]), 0)
     self.assertEquals(response.context["error"], _("The pattern is too short"))
     response = self.client.get("/search/")
     self.assertEquals(len(response.context["object_list"]), 0)
     self.assertEquals(response.context["error"], _("No pattern to search found"))
     restore_template_loaders()
Exemple #21
0
 def test_403_template(self):
     # Set up a test 403.html template.
     setup_test_template_loader(
         {'403.html': 'This is a test template for a 403 Forbidden error.'}
     )
     try:
         response = self.client.get('/views/raises403/')
         self.assertContains(response, 'test template', status_code=403)
     finally:
         restore_template_loaders()
 def test_zinnia_entry_archive_today(self):
     setup_test_template_loader({"zinnia/entry_archive_today.html": ""})
     with self.assertNumQueries(5):
         response = self.client.get("/today/")
     self.assertEquals(response.context["day"], timezone.now().date())
     self.assertTemplateUsed(response, "zinnia/entry_archive_today.html")
     self.assertEquals(response.context["previous_month"], date(2010, 6, 1))
     self.assertEquals(response.context["next_month"], None)
     self.assertEquals(response.context["previous_day"], date(2010, 6, 1))
     self.assertEquals(response.context["next_day"], None)
     restore_template_loaders()
Exemple #23
0
    def tearDown(self):
        import zinnia.xmlrpc.pingback
        zinnia.xmlrpc.pingback.urlopen = self.original_urlopen
        shortener_settings.URL_SHORTENER_BACKEND = self.original_shortener
        restore_template_loaders()

        #Remove this as soon as I figure out why django's not reloading
        #the site properly.
        self.site = Site.objects.get_current()
        self.site.domain = self.old_domain
        self.site.save()
 def test_zinnia_sitemap(self):
     setup_test_template_loader({"zinnia/sitemap.html": ""})
     with self.assertNumQueries(0):
         response = self.client.get("/sitemap/")
     self.assertEquals(len(response.context["entries"]), 2)
     self.assertEquals(len(response.context["categories"]), 1)
     entry = self.create_published_entry()
     entry.categories.add(Category.objects.create(title="New category", slug="new-category"))
     response = self.client.get("/sitemap/")
     self.assertEquals(len(response.context["entries"]), 3)
     self.assertEquals(len(response.context["categories"]), 2)
     restore_template_loaders()
Exemple #25
0
 def test_zinnia_tag_detail(self):
     setup_test_template_loader({
         'zinnia/tag/tests/entry_list.html': '',
         '404.html': ''
     })
     response = self.check_publishing_context('/tags/tests/', 2, 3,
                                              'entry_list', 2)
     self.assertTemplateUsed(response, 'zinnia/tag/tests/entry_list.html')
     self.assertEquals(response.context['tag'].name, 'tests')
     response = self.client.get('/tags/404/')
     self.assertEquals(response.status_code, 404)
     restore_template_loaders()
Exemple #26
0
 def test_zinnia_entry_archive_week(self):
     setup_test_template_loader(
         {'zinnia/archives/2010/week/00/entry_archive_week.html': ''})
     response = self.check_publishing_context(
         '/2010/week/00/', 1, 2, 'entry_list')
     self.assertTemplateUsed(
         response, 'zinnia/archives/2010/week/00/entry_archive_week.html')
     # All days in a new year preceding the first Monday
     # are considered to be in week 0.
     self.assertEquals(response.context['week'], date(2009, 12, 28))
     self.assertEquals(response.context['week_end_day'], date(2010, 1, 3))
     restore_template_loaders()
Exemple #27
0
 def test_zinnia_entry_archive_week(self):
     setup_test_template_loader(
         {'zinnia/archives/2010/week/00/entry_archive_week.html': ''})
     response = self.check_publishing_context('/2010/week/00/', 1, 2,
                                              'entry_list', 1)
     self.assertTemplateUsed(
         response, 'zinnia/archives/2010/week/00/entry_archive_week.html')
     # All days in a new year preceding the first Monday
     # are considered to be in week 0.
     self.assertEquals(response.context['week'], date(2009, 12, 28))
     self.assertEquals(response.context['week_end_day'], date(2010, 1, 3))
     restore_template_loaders()
Exemple #28
0
 def test_zinnia_tag_detail(self):
     setup_test_template_loader(
         {'zinnia/tag/tests/entry_list.html': '',
          '404.html': ''})
     response = self.check_publishing_context(
         '/tags/tests/', 2, 3, 'entry_list', 2)
     self.assertTemplateUsed(
         response, 'zinnia/tag/tests/entry_list.html')
     self.assertEquals(response.context['tag'].name, 'tests')
     response = self.client.get('/tags/404/')
     self.assertEquals(response.status_code, 404)
     restore_template_loaders()
 def tearDown(self):
     """
     Be sure to restore the good urls to use
     if a test fail before restoring the urls.
     """
     self.urls = self.rich_urls
     self._urlconf_setup()
     deactivate()
     try:
         restore_template_loaders()
     except AttributeError:
         pass
Exemple #30
0
 def test_zinnia_category_list(self):
     setup_test_template_loader(
         {'zinnia/category_list.html': ''})
     self.check_publishing_context(
         '/categories/', 1,
         friendly_context='category_list',
         queries=0)
     entry = Entry.objects.all()[0]
     entry.categories.add(Category.objects.create(
         title='New category', slug='new-category'))
     self.check_publishing_context('/categories/', 2)
     restore_template_loaders()
Exemple #31
0
 def test_zinnia_tag_list(self):
     setup_test_template_loader(
         {'zinnia/tag_list.html': ''})
     self.check_publishing_context(
         '/tags/', 1,
         friendly_context='tag_list',
         queries=1)
     entry = Entry.objects.all()[0]
     entry.tags = 'tests, tag'
     entry.save()
     self.check_publishing_context('/tags/', 2)
     restore_template_loaders()
Exemple #32
0
 def test_zinnia_entry_archive_today(self):
     setup_test_template_loader(
         {'zinnia/entry_archive_today.html': ''})
     with self.assertNumQueries(5):
         response = self.client.get('/today/')
     self.assertEquals(response.context['day'], timezone.now().date())
     self.assertTemplateUsed(response, 'zinnia/entry_archive_today.html')
     self.assertEquals(response.context['previous_month'], date(2010, 6, 1))
     self.assertEquals(response.context['next_month'], None)
     self.assertEquals(response.context['previous_day'], date(2010, 6, 1))
     self.assertEquals(response.context['next_day'], None)
     restore_template_loaders()
Exemple #33
0
 def test_zinnia_entry_search(self):
     setup_test_template_loader({'zinnia/entry_search.html': ''})
     self.check_publishing_context('/search/?pattern=test', 2, 3,
                                   'entry_list', 1)
     response = self.client.get('/search/?pattern=ab')
     self.assertEquals(len(response.context['object_list']), 0)
     self.assertEquals(response.context['error'],
                       _('The pattern is too short'))
     response = self.client.get('/search/')
     self.assertEquals(len(response.context['object_list']), 0)
     self.assertEquals(response.context['error'],
                       _('No pattern to search found'))
     restore_template_loaders()
Exemple #34
0
 def test_zinnia_sitemap(self):
     setup_test_template_loader({'zinnia/sitemap.html': ''})
     with self.assertNumQueries(0):
         response = self.client.get('/sitemap/')
     self.assertEquals(len(response.context['entries']), 2)
     self.assertEquals(len(response.context['categories']), 1)
     entry = self.create_published_entry()
     entry.categories.add(
         Category.objects.create(title='New category', slug='new-category'))
     response = self.client.get('/sitemap/')
     self.assertEquals(len(response.context['entries']), 3)
     self.assertEquals(len(response.context['categories']), 2)
     restore_template_loaders()
Exemple #35
0
 def test_zinnia_entry_archive_month(self):
     setup_test_template_loader(
         {'zinnia/archives/2010/month/01/entry_archive_month.html': ''})
     response = self.check_publishing_context('/2010/01/', 1, 2,
                                              'entry_list', 4)
     self.assertTemplateUsed(
         response, 'zinnia/archives/2010/month/01/entry_archive_month.html')
     self.assertEquals(response.context['previous_month'], None)
     self.assertEquals(response.context['next_month'], date(2010, 6, 1))
     restore_template_loaders()
     response = self.client.get('/2010/06/')
     self.assertEquals(response.context['previous_month'], date(2010, 1, 1))
     self.assertEquals(response.context['next_month'], None)
Exemple #36
0
 def test_zinnia_author_list(self):
     setup_test_template_loader({'zinnia/author_list.html': ''})
     self.check_publishing_context('/authors/',
                                   1,
                                   friendly_context='author_list',
                                   queries=0)
     user = Author.objects.create(username='******',
                                  email='*****@*****.**')
     self.check_publishing_context('/authors/', 1)
     entry = Entry.objects.all()[0]
     entry.authors.add(user)
     self.check_publishing_context('/authors/', 2)
     restore_template_loaders()
Exemple #37
0
 def test_zinnia_trackback(self):
     setup_test_template_loader({'404.html': ''})
     response = self.client.post('/trackback/404/')
     self.assertEquals(response.status_code, 404)
     restore_template_loaders()
     self.assertEquals(self.client.post('/trackback/1/').status_code, 301)
     self.assertEquals(self.client.get('/trackback/1/').status_code, 301)
     entry = Entry.objects.get(slug='test-1')
     self.assertEquals(entry.trackback_count, 0)
     entry.trackback_enabled = False
     entry.save()
     self.assertEquals(
         self.client.post('/trackback/1/', {
             'url': 'http://example.com'
         }).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         '<error>1</error>\n  <message>Trackback is not enabled for '
         'Test 1</message>\n  \n</response>\n')
     entry.trackback_enabled = True
     entry.save()
     connect_discussion_signals()
     get_user_flagger()  # Memoize user flagger for stable query number
     if comments.get_comment_app_name() == comments.DEFAULT_COMMENTS_APP:
         # If we are not using the default comment app,
         # we can count the database queries executed.
         with self.assertNumQueries(6):
             self.assertEquals(
                 self.client.post('/trackback/1/', {
                     'url': 'http://example.com'
                 }).content,
                 '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
                 '<error>0</error>\n  \n</response>\n')
     else:
         self.assertEquals(
             self.client.post('/trackback/1/', {
                 'url': 'http://example.com'
             }).content,
             '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
             '<error>0</error>\n  \n</response>\n')
     disconnect_discussion_signals()
     entry = Entry.objects.get(pk=entry.pk)
     self.assertEquals(entry.trackback_count, 1)
     self.assertEquals(
         self.client.post('/trackback/1/', {
             'url': 'http://example.com'
         }).content,
         '<?xml version="1.0" encoding="utf-8"?>\n<response>\n  \n  '
         '<error>1</error>\n  <message>Trackback is already registered'
         '</message>\n  \n</response>\n')
Exemple #38
0
 def test_zinnia_entry_detail(self):
     setup_test_template_loader(
         {'zinnia/_entry_detail.html': '',
          '404.html': ''})
     entry = self.create_published_entry()
     entry.sites.clear()
     response = self.client.get('/2010/01/01/my-test-entry/')
     self.assertEquals(response.status_code, 404)
     entry.template = '_entry_detail.html'
     entry.save()
     entry.sites.add(Site.objects.get_current())
     with self.assertNumQueries(1):
         response = self.client.get('/2010/01/01/my-test-entry/')
     self.assertEquals(response.status_code, 200)
     self.assertTemplateUsed(response, 'zinnia/_entry_detail.html')
     restore_template_loaders()
Exemple #39
0
 def test_zinnia_entry_detail_login(self):
     setup_test_template_loader(
         {'zinnia/entry_detail.html': '',
          'zinnia/login.html': ''})
     entry = self.create_published_entry()
     entry.login_required = True
     entry.save()
     with self.assertNumQueries(4):
         response = self.client.get('/2010/01/01/my-test-entry/')
     self.assertTemplateUsed(response, 'zinnia/login.html')
     response = self.client.post('/2010/01/01/my-test-entry/',
                                 {'username': '******',
                                  'password': '******'})
     self.assertEquals(response.status_code, 200)
     self.assertTemplateUsed(response, 'zinnia/entry_detail.html')
     restore_template_loaders()
Exemple #40
0
 def test_custom_templates(self):
     """
     Test that 404.html and 500.html templates are picked by their respective
     handler.
     """
     setup_test_template_loader(
         {'404.html': 'This is a test template for a 404 error.',
          '500.html': 'This is a test template for a 500 error.'}
     )
     try:
         for code, url in ((404, '/views/non_existing_url/'), (500, '/views/server_error/')):
             response = self.client.get(url)
             self.assertContains(response, "test template for a %d error" % code,
                 status_code=code)
     finally:
         restore_template_loaders()
Exemple #41
0
	def test_templates(self):
		"Tests to make sure that embed behaves with complex includes and extends"
		template_tests = self.get_template_tests()
		
		# Register our custom template loader. Shamelessly cribbed from django/tests/regressiontests/templates/tests.py:384.
		cache_loader = setup_test_template_loader(
			dict([(name, t[0]) for name, t in template_tests.iteritems()]),
			use_cached_loader=True,
		)
		
		failures = []
		tests = template_tests.items()
		tests.sort()
		
		# Turn TEMPLATE_DEBUG off, because tests assume that.
		old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False
		
		# Set TEMPLATE_STRING_IF_INVALID to a known string.
		old_invalid = settings.TEMPLATE_STRING_IF_INVALID
		expected_invalid_str = 'INVALID'
		
		# Run tests
		for name, vals in tests:
			xx, context, result = vals
			try:
				test_template = loader.get_template(name)
				output = test_template.render(template.Context(context))
			except Exception:
				exc_type, exc_value, exc_tb = sys.exc_info()
				if exc_type != result:
					tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
					failures.append("Template test %s -- FAILED. Got %s, exception: %s\n%s" % (name, exc_type, exc_value, tb))
				continue
			if output != result:
				failures.append("Template test %s -- FAILED. Expected %r, got %r" % (name, result, output))
		
		# Cleanup
		settings.TEMPLATE_DEBUG = old_td
		settings.TEMPLATE_STRING_IF_INVALID = old_invalid
		restore_template_loaders()
		
		self.assertEqual(failures, [], "Tests failed:\n%s\n%s" % ('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
Exemple #42
0
 def test_zinnia_tag_detail_paginated(self):
     setup_test_template_loader({'zinnia/entry_list.html': ''})
     for i in range(PAGINATION):
         params = {
             'title': 'My entry %i' % i,
             'content': 'My content %i' % i,
             'slug': 'my-entry-%i' % i,
             'tags': 'tests',
             'creation_date': datetime(2010, 1, 1),
             'status': PUBLISHED
         }
         entry = Entry.objects.create(**params)
         entry.sites.add(self.site)
     response = self.client.get('/tags/tests/')
     self.assertEquals(len(response.context['object_list']), PAGINATION)
     response = self.client.get('/tags/tests/?page=2')
     self.assertEquals(len(response.context['object_list']), 2)
     response = self.client.get('/tags/tests/page/2/')
     self.assertEquals(len(response.context['object_list']), 2)
     self.assertEquals(response.context['tag'].name, 'tests')
     restore_template_loaders()
Exemple #43
0
 def test_zinnia_entry_detail_password(self):
     setup_test_template_loader(
         {'zinnia/entry_detail.html': '',
          'zinnia/password.html': ''})
     entry = self.create_published_entry()
     entry.password = '******'
     entry.save()
     with self.assertNumQueries(1):
         response = self.client.get('/2010/01/01/my-test-entry/')
     self.assertTemplateUsed(response, 'zinnia/password.html')
     self.assertEquals(response.context['error'], False)
     with self.assertNumQueries(4):
         response = self.client.post('/2010/01/01/my-test-entry/',
                                     {'entry_password': '******'})
     self.assertTemplateUsed(response, 'zinnia/password.html')
     self.assertEquals(response.context['error'], True)
     with self.assertNumQueries(5):
         response = self.client.post('/2010/01/01/my-test-entry/',
                                     {'entry_password': '******'})
     self.assertEquals(response.status_code, 200)
     self.assertTemplateUsed(response, 'zinnia/entry_detail.html')
     restore_template_loaders()
Exemple #44
0
 def test_zinnia_author_detail_paginated(self):
     """Test case reproducing issue #207 on author
     detail view paginated"""
     setup_test_template_loader({'zinnia/entry_list.html': ''})
     for i in range(PAGINATION):
         params = {
             'title': 'My entry %i' % i,
             'content': 'My content %i' % i,
             'slug': 'my-entry-%i' % i,
             'creation_date': datetime(2010, 1, 1),
             'status': PUBLISHED
         }
         entry = Entry.objects.create(**params)
         entry.sites.add(self.site)
         entry.authors.add(self.author)
     response = self.client.get('/authors/admin/')
     self.assertEquals(len(response.context['object_list']), PAGINATION)
     response = self.client.get('/authors/admin/?page=2')
     self.assertEquals(len(response.context['object_list']), 2)
     response = self.client.get('/authors/admin/page/2/')
     self.assertEquals(len(response.context['object_list']), 2)
     self.assertEquals(response.context['author'].username, 'admin')
     restore_template_loaders()
Exemple #45
0
 def test_zinnia_category_detail_paginated(self):
     """Test case reproducing issue #42 on category
     detail view paginated"""
     setup_test_template_loader({'zinnia/entry_list.html': ''})
     for i in range(PAGINATION):
         params = {
             'title': 'My entry %i' % i,
             'content': 'My content %i' % i,
             'slug': 'my-entry-%i' % i,
             'creation_date': datetime(2010, 1, 1),
             'status': PUBLISHED
         }
         entry = Entry.objects.create(**params)
         entry.sites.add(self.site)
         entry.categories.add(self.category)
     response = self.client.get('/categories/tests/')
     self.assertEquals(len(response.context['object_list']), PAGINATION)
     response = self.client.get('/categories/tests/?page=2')
     self.assertEquals(len(response.context['object_list']), 2)
     response = self.client.get('/categories/tests/page/2/')
     self.assertEquals(len(response.context['object_list']), 2)
     self.assertEquals(response.context['category'].slug, 'tests')
     restore_template_loaders()
 def tearDown(self):
     try:
         restore_template_loaders()
     except AttributeError:
         pass
Exemple #47
0
 def tearDownClass(cls):
     restore_template_loaders()
 def tearDown(self):
     settings.WYSIWYG = self.original_wysiwyg
     restore_template_loaders()
Exemple #49
0
 def tearDown(self):
     restore_template_loaders()
Exemple #50
0
 def tearDown(self):
     import zinnia.xmlrpc.pingback
     zinnia.xmlrpc.pingback.urlopen = self.original_urlopen
     shortener_settings.URL_SHORTENER_BACKEND = self.original_shortener
     restore_template_loaders()
Exemple #51
0
    def test_templates(self):
        from django.test.utils import setup_test_template_loader
        from django.test.utils import restore_template_loaders

        template_tests = self.get_template_tests()
        filter_tests = {}  #filters.get_filter_tests()

        # Quickly check that we aren't accidentally using a name in both
        # template and filter tests.
        overlapping_names = [name for name in filter_tests if name in template_tests]
        assert not overlapping_names, 'Duplicate test name(s): %s' % ', '.join(overlapping_names)

        template_tests.update(filter_tests)

        cache_loader = setup_test_template_loader(
            dict([(name, t[0]) for name, t in template_tests.iteritems()]),
            use_cached_loader=True,
        )
        failures = []

        # Turn TEMPLATE_DEBUG off, because tests assume that.
        old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False

        # Set TEMPLATE_STRING_IF_INVALID to a known string.
        old_invalid = settings.TEMPLATE_STRING_IF_INVALID
        expected_invalid_str = 'INVALID'

        #Set ALLOWED_INCLUDE_ROOTS so that ssi works.
        old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS
        settings.ALLOWED_INCLUDE_ROOTS = (
            os.path.dirname(os.path.abspath(__file__)),
            )

        try:
            # Openblock: Original code copied from django regression tests
            # didn't have a try/finally block here, which meant any failure
            # below would cause failure to restore template loaders etc.,
            # with disastrous effects for other test suites.
            tests = template_tests.items()
            tests.sort()
            # Warm the URL reversing cache. This ensures we don't pay the cost
            # warming the cache during one of the tests.
            urlresolvers.reverse('ebpub-homepage')

            for name, vals in tests:
                if isinstance(vals[2], tuple):
                    normal_string_result = vals[2][0]
                    invalid_string_result = vals[2][1]

                    if isinstance(invalid_string_result, tuple):
                        expected_invalid_str = 'INVALID %s'
                        invalid_string_result = invalid_string_result[0] % invalid_string_result[1]
                        template_base.invalid_var_format_string = True

                    try:
                        template_debug_result = vals[2][2]
                    except IndexError:
                        template_debug_result = normal_string_result

                else:
                    normal_string_result = vals[2]
                    invalid_string_result = vals[2]
                    template_debug_result = vals[2]

                if 'LANGUAGE_CODE' in vals[1]:
                    activate(vals[1]['LANGUAGE_CODE'])
                else:
                    activate('en-us')
                for invalid_str, template_debug, result in [
                        ('', False, normal_string_result),
                        (expected_invalid_str, False, invalid_string_result),
                        ('', True, template_debug_result)
                    ]:
                    settings.TEMPLATE_STRING_IF_INVALID = invalid_str
                    settings.TEMPLATE_DEBUG = template_debug
                    for is_cached in (False, True):
                        try:
                            try:
                                test_template = loader.get_template(name)
                            except ShouldNotExecuteException:
                                failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))

                            try:
                                output = self.render(test_template, vals)
                            except ShouldNotExecuteException:
                                failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
                        except ContextStackException:
                            failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
                            continue
                        except Exception:
                            exc_type, exc_value, exc_tb = sys.exc_info()
                            if exc_type != result:
                                tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
                                failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
                            continue
                        if output != result:
                            failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Expected %r, got %r" % (is_cached, invalid_str, template_debug, name, result, output))
                    cache_loader.reset()

                if 'LANGUAGE_CODE' in vals[1]:
                    deactivate()

                if template_base.invalid_var_format_string:
                    expected_invalid_str = 'INVALID'
                    template_base.invalid_var_format_string = False
        finally:
            restore_template_loaders()
            deactivate()
            settings.TEMPLATE_DEBUG = old_td
            settings.TEMPLATE_STRING_IF_INVALID = old_invalid
            settings.ALLOWED_INCLUDE_ROOTS = old_allowed_include_roots

        self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
            ('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
Exemple #52
0
 def test_zinnia_entry_channel(self):
     setup_test_template_loader({'zinnia/entry_list.html': ''})
     self.check_publishing_context('/channel-test/', 2, 3, 'entry_list', 1)
     restore_template_loaders()