def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()
        first_item = Item()
        first_item.text = "The first (ever) list item"
        first_item.item_list = list_
        first_item.save()

        second_item = Item()
        second_item.text = "Item the second"
        second_item.item_list = list_
        second_item.save()

        saved_lists = List.objects.first()
        self.assertEqual(saved_lists, 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(first_saved_item.item_list, list_)
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(second_saved_item.item_list, list_)
Exemplo n.º 2
0
    def test_item_is_related_to_list(self):
        item_list = List.objects.create()
        item = Item()

        item.item_list = item_list
        item.save()
        self.assertIn(item, item_list.item_set.all())