def test_displayItems(self): TEMPLATE = "item #%s" for i in range(2): Item.objects.create(text = TEMPLATE %(i)) request = HttpRequest() response = homepage(HttpRequest()) for i in range(2): self.assertIn(TEMPLATE %(i), response.content.decode())
def test_homepage_saves_postRequest(self): response = homepage(self.post(POSTED_ITEM)) self.assertEqual(Item.objects.count(), 1) first = Item.objects.first() self.assertEqual(first.text, POSTED_ITEM) # self.assertIn('A new list item', response.content.decode()) expected = render_to_string('home.html', {'new_item_text': POSTED_ITEM })
def test_emptyPost(self): homepage(HttpRequest()) self.assertEqual(Item.objects.count(), 0)
def test_homepage_redirects_postRequest(self): response = homepage(self.post(POSTED_ITEM)) self.assertEqual(response.status_code, 302) self.assertEqual(response['location'], '/')
def test_homepage_returns_html(self): request = HttpRequest() response = homepage(request) expected = render_to_string('home.html') self.assertEqual(response.content.decode(), expected)