7.11 One More View to Handle Adding Items to an Existing List
parent
29124d8fcd
commit
3b999bda98
|
@ -21,6 +21,35 @@ class NewListTest(TestCase):
|
||||||
new_list = List.objects.first()
|
new_list = List.objects.first()
|
||||||
self.assertRedirects(response=response, expected_url=f'/lists/{new_list.id}/')
|
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):
|
class ListViewTest(TestCase):
|
||||||
|
|
||||||
def test_uses_list_template(self):
|
def test_uses_list_template(self):
|
||||||
|
|
Loading…
Reference in New Issue