|
@@ -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
|
|
|
|
|
|
class HomePageTest(TestCase):
|
|
|
|
|
@@ -28,3 +28,22 @@ class HomePageTest(TestCase):
|
|
|
response = self.client.post('/', data={'item_text': 'A new list item'})
|
|
|
self.assertIn('A new list item', response.content.decode())
|
|
|
self.assertTemplateUsed(response, 'home.html')
|
|
|
+
|
|
|
+class ItemModelTest(TestCase):
|
|
|
+
|
|
|
+ def test_save_and_retrieve_items(self):
|
|
|
+ item1 = Item()
|
|
|
+ item1.text = 'The first (ever) list item'
|
|
|
+ item1.save()
|
|
|
+
|
|
|
+ item2 = Item()
|
|
|
+ item2.text = 'Item the 2nd'
|
|
|
+ item2.save()
|
|
|
+
|
|
|
+ saved = Item.objects.all()
|
|
|
+ self.assertEqual(saved.count(), 2)
|
|
|
+
|
|
|
+ first_item = saved[0]
|
|
|
+ second_item = saved[1]
|
|
|
+ self.assertEqual(first_item.text, item1.text)
|
|
|
+ self.assertEqual(second_item.text, item2.text)
|