Exemplo n.º 1
0
    def test_articles_show_up(self):
        """Assert (multiple) articles show up on the front page."""
        article(title="Improbable").save()
        article(title="Dwarves").save()

        response = self.client.get(reverse("blog.article_list"))
        self.assertContains(response, "Improbable")
        self.assertContains(response, "Dwarves")
Exemplo n.º 2
0
    def test_articles_show_up(self):
        """Assert (multiple) articles show up on the front page."""
        article(title='Improbable').save()
        article(title='Dwarves').save()

        response = self.client.get(reverse('blog.article_list'))
        self.assertContains(response, 'Improbable')
        self.assertContains(response, 'Dwarves')
Exemplo n.º 3
0
    def test_blank_title(self):
        """Assert posting a blank title shows an error."""
        a = article(save=True)
        edit_view = self._edit_view(a.slug)

        self._log_in_as_staff()
        response = self.client.post(edit_view, {'title': '',
                                                'body': 'new body'})
        self.assertContains(response, 'This field is required.')
Exemplo n.º 4
0
    def test_delete(self):
        """Make sure staff can delete articles."""
        a = article(save=True)

        # Make sure editing actually changes the instance:
        self._log_in_as_staff()
        response = self.client.post(reverse('blog.delete_article',
                                            args=[a.slug]),
                                    follow=True)
        eq_(response.status_code, 200)
        assert not Article.objects.all().exists()
Exemplo n.º 5
0
    def test_delete(self):
        """Make sure staff can delete articles."""
        a = article(save=True)

        # Make sure editing actually changes the instance:
        self._log_in_as_staff()
        response = self.client.post(reverse('blog.delete_article',
                                            args=[a.slug]),
                                    follow=True)
        eq_(response.status_code, 200)
        assert not Article.objects.all().exists()
Exemplo n.º 6
0
    def test_blank_title(self):
        """Assert posting a blank title shows an error."""
        a = article(save=True)
        edit_view = self._edit_view(a.slug)

        self._log_in_as_staff()
        response = self.client.post(edit_view, {
            'title': '',
            'body': 'new body'
        })
        self.assertContains(response, 'This field is required.')
Exemplo n.º 7
0
    def test_staff_required(self):
        """Make sure non-staff users can't edit articles."""
        a = article(save=True)
        edit_view = self._edit_view(a.slug)

        # Can't see the edit screen; redirects to login:
        response = self.client.get(edit_view)
        eq_(response.status_code, 302)

        # And can't actually save:
        response = self.client.post(edit_view)
        eq_(response.status_code, 302)
Exemplo n.º 8
0
    def test_edit(self):
        """Make sure staff can edit articles."""
        a = article(save=True)
        edit_view = self._edit_view(a.slug)

        # Make sure editing actually changes the instance:
        self._log_in_as_staff()
        self.client.post(edit_view, {'title': 'new title', 'body': 'new body'})

        changed_article = Article.objects.get(pk=a.pk)
        eq_(changed_article.title, 'new title')
        eq_(changed_article.body, 'new body')
Exemplo n.º 9
0
    def test_staff_required(self):
        """Make sure non-staff users can't edit articles."""
        a = article(save=True)
        edit_view = self._edit_view(a.slug)

        # Can't see the edit screen; redirects to login:
        response = self.client.get(edit_view)
        eq_(response.status_code, 302)

        # And can't actually save:
        response = self.client.post(edit_view)
        eq_(response.status_code, 302)
Exemplo n.º 10
0
    def test_article(self):
        """Assert the article page actually shows the article."""
        a = article(title='Improbable Dwarves',
                    body='These dwarves are highly improbable!',
                    save=True)
        response = self.client.get(
            reverse('blog.article', kwargs={'slug': a.slug}))
        self.assertContains(response, 'Improbable Dwarves')
        self.assertContains(response, 'These dwarves are highly improbable!')


# TODO: Tests for tricky front-page excerpting
Exemplo n.º 11
0
    def test_edit(self):
        """Make sure staff can edit articles."""
        a = article(save=True)
        edit_view = self._edit_view(a.slug)

        # Make sure editing actually changes the instance:
        self._log_in_as_staff()
        self.client.post(edit_view, {'title': 'new title',
                                     'body': 'new body'})

        changed_article = Article.objects.get(pk=a.pk)
        eq_(changed_article.title, 'new title')
        eq_(changed_article.body, 'new body')
Exemplo n.º 12
0
 def test_article(self):
     """Assert the article page actually shows the article."""
     a = article(title="Improbable Dwarves", body="These dwarves are highly improbable!", save=True)
     response = self.client.get(reverse("blog.article", kwargs={"slug": a.slug}))
     self.assertContains(response, "Improbable Dwarves")
     self.assertContains(response, "These dwarves are highly improbable!")
Exemplo n.º 13
0
 def test_unicode(self):
     """Make sure the ``__unicode__`` method returns the title."""
     result = unicode(article(title='Hi There'))
     eq_(type(result), type(u''))
     eq_(result, u'Hi There')
Exemplo n.º 14
0
 def test_unicode(self):
     """Make sure the ``__unicode__`` method returns the title."""
     result = unicode(article(title="Hi There"))
     eq_(type(result), type(u""))
     eq_(result, u"Hi There")