diff --git a/src/lists/tests.py b/src/lists/tests.py index 4c1dab6..d3fa49c 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -1,11 +1,6 @@ -from typing import Text -from django.http import response from django.test import TestCase -from django.urls import resolve -from django.http import HttpRequest -from lists.views import home_page -from lists.models import Item +from lists.models import Item, List class HomePageTest(TestCase): @@ -44,21 +39,32 @@ class ListViewTest(TestCase): self.assertContains(response, 'itemey 1') self.assertContains(response, 'itemey 2') -class ItemModelTest(TestCase): +class ListAndItemModelsTest(TestCase): def test_saving_and_retrieving_items(self): + + list_ = List() + list_.save() + first_item = Item() # Create an object first_item.text = 'The first (ever) list item' # Assign attributes + first_item.list = list_ first_item.save() # Calling .save() function second_item = Item() second_item.text = 'Item the second' + second_item.list = list_ second_item.save() + saved_list = List.objects.first() + self.assertEqual(saved_list, list_) + saved_items = Item.objects.all() self.assertEqual(saved_items.count(), 2) first_saved_item = saved_items[0] second_saved_item = saved_items[1] self.assertEqual(first_saved_item.text, 'The first (ever) list item') - self.assertEqual(second_saved_item.text, 'Item the second') \ No newline at end of file + self.assertEqual(first_saved_item.list, list_) + self.assertEqual(second_saved_item.text, 'Item the second') + self.assertEqual(second_saved_item.list, list_) \ No newline at end of file