|
@@ -26,8 +26,28 @@ class HomePageTest(TestCase):
|
|
|
|
|
|
def test_can_save_POST_request(self):
|
|
|
response = self.client.post('/', data={'item_text': 'A new list item'})
|
|
|
- self.assertIn('A new list item', response.content.decode())
|
|
|
- self.assertTemplateUsed(response, 'home.html')
|
|
|
+
|
|
|
+ self.assertEqual(Item.objects.count(), 1)
|
|
|
+ new_item = Item.objects.first()
|
|
|
+ self.assertEqual(new_item.text, 'A new list item')
|
|
|
+
|
|
|
+ def test_redirects_after_POST(self):
|
|
|
+ response = self.client.post('/', data={'item_text': 'A new list item'})
|
|
|
+ self.assertEqual(response.status_code, 302)
|
|
|
+ self.assertEqual(response['location'], '/')
|
|
|
+
|
|
|
+ def test_only_saves_items_when_needed(self):
|
|
|
+ self.client.get('/')
|
|
|
+ self.assertEqual(Item.objects.count(), 0)
|
|
|
+
|
|
|
+ def test_displays_all_items(self):
|
|
|
+ Item.objects.create(text='itemey 1')
|
|
|
+ Item.objects.create(text='itemey 2')
|
|
|
+
|
|
|
+ response = self.client.get('/')
|
|
|
+
|
|
|
+ self.assertIn('itemey 1', response.content.decode())
|
|
|
+ self.assertIn('itemey 2', response.content.decode())
|
|
|
|
|
|
class ItemModelTest(TestCase):
|
|
|
|