7.10 Each List Should Have Its Own URL

chap7-new
Jason Zhu 2020-11-11 14:52:09 +11:00
parent 6515ab1dc7
commit df26c82490
1 changed files with 12 additions and 5 deletions

View File

@ -23,18 +23,25 @@ class NewListTest(TestCase):
class ListViewTest(TestCase):
def test_uses_list_template(self):
response = self.client.get('/lists/the-only-list-in-the-world/')
list_ = List.objects.create()
response = self.client.get('/lists/{list_.id}/')
self.assertTemplateUsed(response=response, template_name='list.html')
def test_displays_all_items(self):
list_ = List.objects.create()
Item.objects.create(text="itemey 1", list=list_)
Item.objects.create(text="itemey 2", list=list_)
correct_list = List.objects.create()
Item.objects.create(text="itemey 1", list=correct_list)
Item.objects.create(text="itemey 2", list=correct_list)
other_list = List.objects.create()
Item.objects.create(text="other list item 1", list=other_list)
Item.objects.create(text="other list item 2", list=other_list)
response = self.client.get('/lists/the-only-list-in-the-world/')
response = self.client.get('/lists/{correct_list.id}/')
self.assertContains(response, 'itemey 1')
self.assertContains(response, 'itemey 2')
self.assertContains(response=response, text='other list item 1')
self.assertContains(response=response, text='other list item 2')
class ListAndItemModelsTest(TestCase):