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")
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')
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.')
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()
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.')
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)
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')
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
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!")
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')
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")