From 24fb7b1e09f9b544f9adf4c73e635a09beb021e8 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Wed, 11 Nov 2020 14:27:11 +1100 Subject: [PATCH] 7.8.1 A Test Class for New List Creation --- src/lists/tests.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lists/tests.py b/src/lists/tests.py index 452ad5d..4c1dab6 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -13,22 +13,21 @@ class HomePageTest(TestCase): response = self.client.get('/') self.assertTemplateUsed(response, 'home.html') - def test_can_save_a_POST_request(self): - self.client.post('/', data={'item_text': 'A new list item'}) + def test_only_saves_items_when_necessary(self): + self.client.get('/') + self.assertEqual(Item.objects.count(), 0) +class NewListTest(TestCase): + + def test_can_save_a_POST_request(self): + self.client.post('/lists/new', data={'item_text': 'A new list item'}) 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'], '/lists/the-only-list-in-the-world') - - def test_only_saves_items_when_necessary(self): - self.client.get('/') - self.assertEqual(Item.objects.count(), 0) + response = self.client.post('/lists/new', data={'item_text': 'A new list item'}) + self.assertRedirects(response=response, expected_url='/lists/the-only-list-in-the-world/') class ListViewTest(TestCase):