7.10.2 Adjusting new_list to the New World (w/ bug fix)

This commit is contained in:
Jason Zhu 2020-11-11 15:04:49 +11:00
parent 434e66e0ae
commit 29124d8fcd
2 changed files with 8 additions and 7 deletions

View File

@ -18,16 +18,17 @@ class NewListTest(TestCase):
def test_redirects_after_POST(self):
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/')
new_list = List.objects.first()
self.assertRedirects(response=response, expected_url=f'/lists/{new_list.id}/')
class ListViewTest(TestCase):
def test_uses_list_template(self):
list_ = List.objects.create()
response = self.client.get('/lists/{list_.id}/')
response = self.client.get(f'/lists/{list_.id}/')
self.assertTemplateUsed(response=response, template_name='list.html')
def test_displays_all_items(self):
def test_displays_only_items_for_that_list(self):
correct_list = List.objects.create()
Item.objects.create(text="itemey 1", list=correct_list)
Item.objects.create(text="itemey 2", list=correct_list)
@ -36,12 +37,12 @@ class ListViewTest(TestCase):
Item.objects.create(text="other list item 2", list=other_list)
response = self.client.get('/lists/{correct_list.id}/')
response = self.client.get(f'/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')
self.assertNotContains(response=response, text='other list item 1')
self.assertNotContains(response=response, text='other list item 2')
class ListAndItemModelsTest(TestCase):

View File

@ -14,4 +14,4 @@ def view_list(request, list_id):
def new_list(request):
list_ = List.objects.create()
Item.objects.create(text=request.POST['item_text'], list=list_)
return redirect('/lists/the-only-list-in-the-world/')
return redirect(f'/lists/{list_.id}/')