diff --git a/src/lists/tests.py b/src/lists/tests.py index 277835f..e78f3d9 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -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): diff --git a/src/lists/views.py b/src/lists/views.py index c35c7d8..f00b775 100644 --- a/src/lists/views.py +++ b/src/lists/views.py @@ -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/') \ No newline at end of file + return redirect(f'/lists/{list_.id}/') \ No newline at end of file