Exemplo n.º 1
0
    def test_saving_and_retrieving_items(self):
        the_list = List()
        the_list.save()
        item1 = Item()
        item1.text = 'The first (ever) list item'
        item1.list = the_list
        item1.save()

        item2 = Item()
        item2.text = 'Item the second'
        item2.list = the_list
        item2.save()

        saved_list = List.objects.first()
        self.assertEqual(saved_list, the_list)

        saved_items = Item.objects.all()
        self.assertEqual(saved_items.count(), 2)

        saved_item1 = saved_items[0]
        saved_item2 = saved_items[1]

        self.assertEqual(saved_item1.text, 'The first (ever) list item')
        self.assertEqual(saved_item1.list, the_list)
        self.assertEqual(saved_item2.text, 'Item the second')
        self.assertEqual(saved_item2.list, the_list)
Exemplo n.º 2
0
    def test_saving_and_retrieving_items(self):
        first_item_text = 'The first (ever) list item'
        second_item_text = 'The second item'

        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = first_item_text
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = second_item_text
        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, first_item_text)
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, second_item_text)
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 3
0
    def testSavingAndRetrievingItems(self):
        myList = List()
        myList.save()

        firstItem = Item()
        firstItem.text = 'The first list item'
        firstItem.list = myList
        firstItem.save()

        secondItem = Item()
        secondItem.text = 'The second list item'
        secondItem.list = myList
        secondItem.save()

        savedItems = Item.objects.all()
        self.assertEqual(savedItems.count(),2)

        savedLists = List.objects.first()
        self.assertEqual(savedLists, myList)

        firstSavedItem = savedItems[0]
        secondSavedItem = savedItems[1]
        self.assertEqual(firstSavedItem.text,'The first list item')
        self.assertEqual(secondSavedItem.text,'The second list item')
        self.assertEqual(firstSavedItem.list, myList)
        self.assertEqual(secondSavedItem.list, myList)
Exemplo n.º 4
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = "The First (Ever) List Item"
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = "The Second Item"
        second_item.list = list_
        second_item.save()

        saved_objects = Item.objects.all()
        self.assertEqual(saved_objects.count(),2)
        saved_list = List.objects.first()
        self.assertEqual(saved_list,list_)

        first_saved_item = saved_objects[0]
        second_saved_item = saved_objects[1]

        self.assertEqual(first_saved_item.text,'The First (Ever) List Item')
        self.assertEqual(first_saved_item.list,list_)
        self.assertEqual(second_saved_item.list,list_)
        self.assertEqual(second_saved_item.text,'The Second Item')
Exemplo n.º 5
0
	def test_saving_and_retrieving_items(self):
		list_ = List()
		list_.save()

		first_item = Item()
		first_item.text = 'The first (ever) list item'
		first_item.list = list_
		first_item.save()

		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(first_saved_item.list, list_)
		self.assertEqual(second_saved_item.text, 'Item the second')
		self.assertEqual(second_saved_item.list, list_)

		def test_cannot_save_empty_list_items(self):
			list_ = List.objects.create()
			item = Item(list=list_, text='')
			with self.assertRaises(ValidationError):
				item.save()
				item.full_clean()
Exemplo n.º 6
0
    def test_saving_and_retrieving_item(self):
        list_ = List()
        list_.save()
        self.assertEqual(1, List.objects.count())

        first_item = Item()
        first_item.text = 'First item text';
        first_item.list = list_
        first_item.save()
        
        second_item = Item()
        second_item.text = 'Second item text';
        second_item.list = list_
        second_item.save()

        saved_list = List.objects.first()
        self.assertEqual(list_, saved_list)

        saved_items = Item.objects.all()
        self.assertEqual(2, Item.objects.count())

        first_saved_item = saved_items[0]
        second_saved_item = saved_items[1]
        self.assertEqual('First item text', first_saved_item.text)
        self.assertEqual('Second item text', second_saved_item.text)

        self.assertEqual(list_, first_item.list)
        self.assertEqual(list_, second_item.list)
Exemplo n.º 7
0
Arquivo: tests.py Projeto: FilgeN/TDD
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = 'Absolutnie pierwszy element listy'
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = 'Drugi element'
        second_item.list = list_
        second_item.save()

        saved_list = List.objects.first()
        self.assertEqual(saved_list, list_)

        saved_items = Item.objects.all()  # zwraca QuerySet
        self.assertEqual(saved_items.count(), 2)

        first_saved_item = saved_items[0]
        second_saved_item = saved_items[1]

        self.assertEqual(first_saved_item.text, 'Absolutnie pierwszy element listy')
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'Drugi element')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 8
0
    def test_saving_and_retrieving_items(self):
        #python ma wbudowaną funkcję list
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = 'The first (ever) list item'
        #w ten sposób tworzone jest powiązanie do listy
        #pod atrybutem list kryje się adres, do którego linkuje element listy list_ - moje wyjaśnienie
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = 'Item the second'
        second_item.list = list_
        second_item.save()

        saved_list = List.objects.first()
        #porównanie kluczy głównych (atrybut id)
        self.assertEqual(saved_list, list_)

        #objects to atrybut klasy modelu, tu np. Item
        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.list, list_)
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 9
0
    def test_saving_and_retrieving_items(self):
        item_list = List()
        item_list.save()

        first_item = Item()
        first_item_text = "The first (ever) list item"
        first_item.text = first_item_text
        first_item.list = item_list
        first_item.save()

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

        saved_list = List.objects.first()
        self.assertEqual(saved_list, item_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, first_item_text)
        self.assertEqual(first_saved_item.list, item_list)
        self.assertEqual(second_saved_item.text, second_item_text)
        self.assertEqual(second_saved_item.list, item_list)
Exemplo n.º 10
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = 'The first list item EVER'
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = 'Second thing on the agenda'
        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 list item EVER')
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'Second thing on the agenda')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 11
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = "My first list item"
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = "A fancy second item"
        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, 'My first list item')
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'A fancy second item')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 12
0
    def test_saving_and_retrieving_items(self):
        # make a new list, save it.
        # create the first item, save it. Assign its list field as the newly created list.
        # Same for the second item.
        # Get the first list from the db.
        # assert it's equal to the originally created list.
        # get the two items from the db.
        # assert that their list is the created list.

        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = "The first item"
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = "the second Item, wow!"
        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, first_item.text)
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, second_item.text)
        self.assertEqual(second_saved_item.list, list_)
    def test_saving_and_retrieving_items_in_list(self):
        new_list = List()
        new_list.save()

        # call constructor as function and returns instance of object, don't need new instance
        first_item = Item()
        first_item.text = 'The first (ever) list item'
        # At this line, what is first_item.list ???
        first_item.list = new_list
        first_item.save()

        second_item = Item()
        second_item.text = 'Item the second'
        second_item.list = new_list
        second_item.save()

        # retrieve saved items
        saved_list = List.objects.first()
        self.assertEqual(new_list, saved_list)

        saved_items = Item.objects.all()
        self.assertEqual(saved_items.count(), 2)

        #check that items line up
        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')
        self.assertEqual(first_saved_item.list, new_list)
        self.assertEqual(second_saved_item.list, new_list)
Exemplo n.º 14
0
	def test_saving_and_retrieving_items(self):
		first_item_text = 'First List Item'
		second_item_text = 'Second List Item'
		## Create a new List object
		list_ = List()
		list_.save()
		
		first_item = Item()
		first_item.text = first_item_text
		## assign each item to the List object by assigning it as its .list property.
		first_item.list = list_
		first_item.save()

		second_item = Item()
		second_item.text = second_item_text
		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, first_item_text)
		self.assertEqual(first_saved_item.list, list_)
		self.assertEqual(second_saved_item.text, second_item_text)
		self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 15
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()
        
        first_item = Item()
        first_item.text = 'The first (ever) list item'
        first_item.list = list_ #Assign item to newly created List object
        first_item.save()

        second_item = Item()
        second_item.text = 'Item the second'
        second_item.list = list_
        second_item.save()

        #Check list_ is properly saved
        saved_list = List.objects.first()
        self.assertEqual(saved_list, list_)

        saved_items = Item.objects.all() #Django API for querying db for all records in Item table
        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.list, list_) #Check item has saved relationship to list_
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 16
0
    def test_saving_and_retrieving_items(self):
        """
        Test that text can be added to item model and saved to a list.

        Creates a list and save it. Then, creates two items linked to
        the list. Finally, the test checks for expected text and
        the correct number of items in the list.
        """
        list_ = List()  # use 'list_' to avoid built-in clash
        list_.save()

        first_item = Item()
        first_item.text = 'The first (ever) list item'
        first_item.list = list_
        first_item.save()

        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(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 17
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = 'The first (ever) list item'
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = 'Item the second'
        second_item.list = list_
        second_item.save()

        # Check list was saved correctly
        saved_list = List.objects.first()
        self.assertEqual(saved_list, list_)

        # Check 2 items were saved correctly
        saved_items = Item.objects.all()
        self.assertEqual(saved_items.count(), 2)

        # Ensure text was saved correctly, also list item pointers to list
        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.list, list_)
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(first_saved_item.list, list_)
Exemplo n.º 18
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = "First ever list item"
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = "Second item"
        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 = saved_items[0]
        second_saved = saved_items[1]
        self.assertEqual(first_saved.text, first_item.text)
        self.assertEqual(first_saved.list, list_)
        self.assertEqual(second_saved.text, second_item.text)
        self.assertEqual(second_saved.list, list_)
Exemplo n.º 19
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()
        first_item = Item()
        first_item.text = u"족발과 새우젓"
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = u"쌈도 샀니?"
        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]
        self.assertEqual(u"족발과 새우젓", first_saved_item.text)
        self.assertEqual(list_, first_saved_item.list)

        second_saved_item = saved_items[1]
        self.assertEqual(list_, second_saved_item.list)
        self.assertEqual(u"쌈도 샀니?", second_saved_item.text)
Exemplo n.º 20
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = "The first (ever) list item"
        first_item.list = list_
        first_item.save()

        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(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, "Item the second")
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 21
0
	def test_saving_and_retrieving_items(self):
		list_ = List()
		list_.save()

		first_item = Item()
		first_item.text = 'The first (ever) list item'
		first_item.list = list_
		first_item.save()
		
		second_item = Item()
		second_item.text = 'Item the second'
		second_item.list = list_
		second_item.save()

		saved_lists = List.objects.all()
		self.assertEqual(saved_lists.count(), 1)
		self.assertEqual(saved_lists[0], 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.list, list_)
		self.assertEqual(second_saved_item.text, 'Item the second')
		self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 22
0
    def test_saving_and_retrieving_items(self):
        list = List()
        list.save()

        first = Item()
        first.text = 'The first list item'
        first.list = list
        first.save()

        second = Item()
        second.text = 'Second item'
        second.list = list
        second.save()

        saved_lists = List.objects.all()
        self.assertEqual(saved_lists.count(), 1)
        self.assertEqual(saved_lists[0], 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, first.text)
        self.assertEqual(first_saved_item.list, list)
        self.assertEqual(second_saved_item.text, second.text)
        self.assertEqual(second_saved_item.list, list)
Exemplo n.º 23
0
	def test_saving_and_retrieving_items(self):
		my_list = List()
		my_list.save()

		first_item = Item()
		first_item.text = 'The first (ever) list item'
		first_item.list = my_list
		first_item.save()

		second_item = Item()
		second_item.text = 'The second item'
		second_item.list = my_list
		second_item.save()

		saved_list = List.objects.first()
		self.assertEqual(saved_list, my_list)

		saved_items = Item.objects.all()
		self.assertEquals(saved_items.count(), 2)

		retrieved_first_item = saved_items[0]
		retrieved_second_item = saved_items[1]
		self.assertEqual(retrieved_first_item.text, first_item.text)
		self.assertEqual(retrieved_first_item.list, my_list)
		self.assertEqual(retrieved_second_item.text, second_item.text)
		self.assertEqual(retrieved_second_item.list, my_list)
Exemplo n.º 24
0
	def test_saving_and_retrieving_items(self):
		list_ = List()
		list_.save()

		first_item = Item()
		first_item.text = 'The first (ever) list item'
		first_item.list = list_ 
		first_item.save()

		second_item = Item()
		second_item.text = 'Second list item'
		second_item.list = list_
		second_item.save()

		saved_list = List.objects.first()
		self.assertEqual(saved_list, list_) # check that the id is the same

		saved_items = Item.objects.all() # returns a list? - actually a QuerySet
		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.list , list_)
		self.assertEqual(second_saved_item.text , 'Second list item')
		self.assertEqual(second_saved_item.list , list_)
Exemplo n.º 25
0
    def test_saving_and_retrieving_items(self):

        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = '첫 번째 아이템'
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = '두 번째 아이템'
        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, '첫 번째 아이템')
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, '두 번째 아이템')
        self.assertEqual(first_saved_item.list, list_)
Exemplo n.º 26
0
    def test_saving_and_retrieving_items(self):
        # classes are dbs, create hear see lists.models for class defn
        list_ = List()
        list_.save()

        first_item = Item()
        # instances are cols ie text column
        first_item.text = 'The first (ever) list item'
        first_item.list = list_
        # create object at this row
        first_item.save()

        second_item = Item()
        second_item.text = 'Item the second'
        second_item.list = list_
        second_item.save()

        saved_items = List.objects.first()
        self.assertEqual(saved_items, list_)

        # use .objects to acc all data, returns list like obj
        saved_items = Item.objects.all()
        self.assertEqual(saved_items.count(), 2)

        first_saved_item = saved_items[0]
        second_saved_item = saved_items[1]
        # check to see if db object returns is recovered correctly
        self.assertEqual(first_saved_item.text, 'The first (ever) list item')
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 27
0
    def test_saving_and_retrieving_items(self):
        the_list = List()
        the_list.save()

        first_item = Item()
        first_item.text = 'The first ever item in the list'
        first_item.list = the_list
        first_item.save()

        second_item = Item()
        second_item.text = 'Item namba two'
        second_item.list = the_list
        second_item.save()

        saved_list = List.objects.first()
        self.assertEqual(saved_list, the_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 item in the list')
        self.assertEqual(first_saved_item.list, the_list)
        self.assertEqual(second_saved_item.text,
                         'Item namba two')
        self.assertEqual(second_saved_item.list, the_list)
Exemplo n.º 28
0
    def test_saving_and_retrieving_items(self):
        ## using list_ (with underscore at end) to avoid "shadowing"
        ## the Python builtin 'list' function (its ugly, oh well)
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = 'The first (ever) list item'
        first_item.list = list_
        first_item.save()

        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(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(second_saved_item.list, list_)
Exemplo n.º 29
0
 def test_saving_and_retrieving_items(self):
     list_ = List()
     list_.save()
     
     firstItem = Item()
     firstItem.text = '第一個清單項目'
     firstItem.list = list_
     firstItem.save()
     
     secondItem = Item()
     secondItem.text = '第二個清單項目'
     secondItem.list = list_
     secondItem.save()
     
     savedList = List.objects.first()
     self.assertEqual(savedList, list_)
     
     savedItems = Item.objects.all()
     self.assertEqual(savedItems.count(), 2)
     
     firstSavedItem = savedItems[0]
     secondSavedItem = savedItems[1]
     self.assertEqual(firstSavedItem.text, '第一個清單項目')
     self.assertEqual(firstSavedItem.list, list_)
     self.assertEqual(secondSavedItem.text, '第二個清單項目')
     self.assertEqual(secondSavedItem.list, list_)
Exemplo n.º 30
0
    def test_saving_and_retrieving_items(self):
        new_list = List()
        new_list.save()

        first_item = Item()
        first_item.text = 'The first (ever) list item'
        first_item.list = new_list
        first_item.save()

        second_item = Item()
        second_item.text = 'Item the second'
        second_item.list = new_list   # equals to adding item to the new_list
        second_item.save()

        saved_list = List.objects.first()
        self.assertEqual(new_list, saved_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')
        self.assertEqual(first_saved_item.list, new_list)
        self.assertEqual(second_saved_item.list, new_list)
Exemplo n.º 31
0
 def testItemIsRelatedToList(self):
     theList = List.objects.create()
     item = Item()
     item.list = theList
     item.save()
     self.assertIn(item, theList.item_set.all())
Exemplo n.º 32
0
 def test_item_is_related_to_list(self):
     list_ = List.objects.create()
     item = Item()
     item.list = list_
     item.save()
     self.assertIn(item, list_.item_set.all())