|
@@ -4,7 +4,7 @@ from django.http import HttpRequest
|
|
|
from django.template.loader import render_to_string
|
|
|
|
|
|
from lists.views import home_page
|
|
|
-from lists.models import Item
|
|
|
+from lists.models import Item, List
|
|
|
|
|
|
class HomePageTest(TestCase):
|
|
|
|
|
@@ -51,24 +51,33 @@ class ListViewTest(TestCase):
|
|
|
self.assertContains(response, 'itemey 1')
|
|
|
self.assertContains(response, 'itemey 2')
|
|
|
|
|
|
-class ItemModelTest(TestCase):
|
|
|
+class ListAndItemModelsTest(TestCase):
|
|
|
|
|
|
def test_save_and_retrieve_items(self):
|
|
|
+ list_ = List()
|
|
|
+ list_.save()
|
|
|
item1 = Item()
|
|
|
item1.text = 'The first (ever) list item'
|
|
|
+ item1.list = list_
|
|
|
item1.save()
|
|
|
|
|
|
item2 = Item()
|
|
|
item2.text = 'Item the 2nd'
|
|
|
+ item2.list = list_
|
|
|
item2.save()
|
|
|
|
|
|
- saved = Item.objects.all()
|
|
|
- self.assertEqual(saved.count(), 2)
|
|
|
+ savedL = List.objects.first()
|
|
|
+ self.assertEqual(savedL, list_)
|
|
|
|
|
|
- first_item = saved[0]
|
|
|
- second_item = saved[1]
|
|
|
+ savedI = Item.objects.all()
|
|
|
+ self.assertEqual(savedI.count(), 2)
|
|
|
+
|
|
|
+ first_item = savedI[0]
|
|
|
+ second_item = savedI[1]
|
|
|
self.assertEqual(first_item.text, item1.text)
|
|
|
+ self.assertEqual(first_item.list, list_)
|
|
|
self.assertEqual(second_item.text, item2.text)
|
|
|
+ self.assertEqual(second_item.list, list_)
|
|
|
|
|
|
class NewListTest(TestCase):
|
|
|
|