diff --git a/src/lists/tests.py b/src/lists/tests.py index e78f3d9..56bfe48 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -21,6 +21,35 @@ class NewListTest(TestCase): new_list = List.objects.first() self.assertRedirects(response=response, expected_url=f'/lists/{new_list.id}/') +class NewItemTest(TestCase): + + def test_can_save_a_POST_request_to_an_existing_list(self): + other_list = List.objects.create() + correct_list = List.objects.create() + + self.client.post( + f'/lists/{correct_list.id}/add_item', + data={'item_text': 'A new item for an existing list'} + ) + + self.assertEqual(Item.objects.count(), 1) + new_item = Item.objects.first() + self.assertEqual(new_item.text, 'A new item for an existing list') + self.assertEqual(new_item.list, correct_list) + + def test_redirects_to_list_view(self): + other_list = List.objects.create() + correct_list = List.objects.create() + + response = self.client.post( + f'/lists/{correct_list.id}/add_item', + data={'item_text': 'A new item for an existing list'} + ) + + self.assertRedirects( + response=response, + expected_url=f'/lists/{correct_list.id}/') + class ListViewTest(TestCase): def test_uses_list_template(self):