Пример #1
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_)
Пример #2
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)
Пример #3
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)
Пример #4
0
    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_)
Пример #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_)
Пример #6
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_)
Пример #7
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_)
Пример #8
0
    def test_CAN_save_same_item_to_different_lists(self):
        list1  = List.objects.create()
        list2  = List.objects.create()

        Item.objects.create(list=list1, text='bla')
        item = Item(list=list2, text='bla')
        item.full_clean() #에러를 발생시키지 않는다.
Пример #9
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)
Пример #10
0
def home_page(request):
    item = Item()
    item.text = request.POST.get('item_text', '')
    item.save()
    return render(request, 'home.html', {
        'new_item_text': item.text
    })
Пример #11
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_)
Пример #12
0
 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()
Пример #13
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_)
Пример #14
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)
Пример #15
0
	def test_duplicate_items_are_invalid(self):
		list_ = List.objects.create()
		Item.objects.create(list=list_,text='bla')
		with self.assertRaises(ValidationError):
			item = Item(list=list_,text='bla')
			item.full_clean()
			item.save()
Пример #16
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_)
Пример #17
0
 def test_cannot_save_empty_list_items(self):
     '''item.save()를 실행시(빈 리스트 저장되는지 테스트하는거니까) ValidationError가 발생해야 한다'''
     list_ = List.objects.create()
     item = Item(list=list_, text='')
     with self.assertRaises(ValidationError):
         item.save()
         item.full_clean()
Пример #18
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)
Пример #19
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_)
Пример #20
0
 def test_item_is_related_to_list(self):
     # making sure foreign key relationship works
     list_ = List.objects.create()
     item = Item()
     item.list = list_
     item.save()
     self.assertIn(item, list_.item_set.all())
Пример #21
0
 def test_item_is_related_to_list(self):
     list_ = List.objects.create()
     item = Item(text='some text')
     item.list = list_
     item.save()
     # reverse queryset
     self.assertIn(item, list_.item_set.all())
Пример #22
0
def view_list(request, list_id):
    # to-do list
    list_ = List.objects.get(id = list_id)
    error = None
    # A list of all items in the to-do list
    # items = Item.objects.filter(list = list_)

    # Method == 'POST'
    if request.method == 'POST':
        if request.POST.has_key('item_text'):
            try:
                item = Item(text=request.POST['item_text'], list=list_)
                item.full_clean()
                item.save()

            except ValidationError:
                error = "You can't have an empty list item"

        if request.POST.has_key('list_name'):
            list_.name = request.POST['list_name']
            list_.save()

    # Method == 'GET'
    return render(
        request,
        'list.html',
        {'list': list_, 'error': error}
    )
Пример #23
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_)
Пример #24
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)
Пример #25
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)
Пример #26
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()
Пример #27
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_)
Пример #28
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_)
Пример #29
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')
Пример #30
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)
Пример #31
0
 def test_cannot_save_empty_list_items(self):
     list_ = List.objects.create()
     item = Item(list=list_, text='')
     with self.assertRaises(ValidationError):
         item.full_clean()  # test to warn if we forget to set blank=True
         item.save()
Пример #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())
Пример #33
0
 def test_defaut_text(self):
     item = Item()
     self.assertEqual(item.text, '')
Пример #34
0
 def test_duplicate_items_are_invalid(self):
     list_ = List.objects.create()
     Item.objects.create(list=list_, text='bla')
     with self.assertRaises(ValidationError):
         item = Item(list=list_, text='bla')
         item.full_clean()
Пример #35
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_)
Пример #36
0
 def test_string_representation(self):
     item = Item(text='some text')
     self.assertEqual(str(item), 'some text')
Пример #37
0
 def test_CAN_save_same_item_to_different_lists(self):
     list1 = List.objects.create()
     list2 = List.objects.create()
     Item.objects.create(list=list1, text='bla')
     item = Item(list=list2, text='bla')
     item.full_clean()  # should not raise
Пример #38
0
    def test_saving_and_retriving_items(self):

        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = self.item_1
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = self.item_2
        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.item_1)
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, self.item_2)
        self.assertEqual(second_saved_item.list, list_)
Пример #39
0
 def test_default_text(self) -> None:
     """Test default text correctly rendered."""
     item = Item()
     self.assertEqual(item.text, "")
Пример #40
0
 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()
Пример #41
0
    def test_saving_and_retrieving_items(self):
        my_list = List()
        my_list.save()

        first_item = Item()
        first_item.text = 'O primeiro item'
        first_item.list = my_list
        first_item.save()

        second_item = Item()
        second_item.text = 'O segundo 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.assertEqual(saved_items.count(), 2)

        first_saved_item = saved_items[0]
        second_saved_item = saved_items[1]
        self.assertEqual(first_saved_item.text, 'O primeiro item')
        self.assertEqual(first_saved_item.list, my_list)
        self.assertEqual(second_saved_item.text, 'O segundo item')
        self.assertEqual(second_saved_item.list, my_list)
Пример #42
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(second_saved_item.list, list_)
Пример #43
0
 def test_can_save_same_item_to_different_lists(self):
     list1 = List.objects.create()
     list2 = List.objects.create()
     Item.objects.create(list=list1, text='ata')
     item = Item(list=list2, text='ata')
     item.full_clean()
Пример #44
0
 def test_string_representation(self) -> None:
     """Test the string representation of items."""
     item = Item(text="some text")
     self.assertEqual(str(item), "some text")
Пример #45
0
	def test_saving_and_retrieving_items(self):
		list_ = List()
		list_.save()

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

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

		saved_list = List.objects.first()
		""" Behind the scenes, saved_list and list_
			compare against each other using their primary key """
		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')
		self.assertEqual(first_saved_item.list, list_)
		self.assertEqual(second_saved_item.text, 'The second list item')
		self.assertEqual(second_saved_item.list, list_)
Пример #46
0
    def test_saving_and_retrieving_items(self):
        # list_ = List()
        # list_.save()

        list_ = List.objects.create()

        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 item, directly after first'
        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('The first (ever) list item', first_saved_item.text)
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual('Second item, directly after first',
                         second_saved_item.text)
        self.assertEqual(second_saved_item.list, list_)
Пример #47
0
 def test_string_representation(self):
     '''тест строкового представления'''
     item = Item(text='some text')
     self.assertEqual(str(item), 'some text')
Пример #48
0
    def test_saving_and_retrieving_items(self):
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = 'O primeiro (de todos) item da lista'
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = 'Item o segundo'
        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,
                         'O primeiro (de todos) item da lista')
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'Item o segundo')
        self.assertEqual(second_saved_item.list, list_)
Пример #49
0
 def test_string_representation(self):
     item = Item(text='Joe Abercrombie')
     self.assertEqual(str(item), 'Joe Abercrombie')
Пример #50
0
    def test_saving_and_retrieving_item(self):
        '''тест сохранения и получения элементов списка'''
        list_ = List()
        list_.save()

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

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

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

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

        first_saved_item = saved_item[0]
        second_saved_item = saved_item[1]
        self.assertEqual(first_saved_item.text, 'The first (ever) list item')
        self.assertEqual(first_saved_item.list1, list_)
        self.assertEqual(second_saved_item.text, 'Item the second')
        self.assertEqual(second_saved_item.list1, list_)
Пример #51
0
    def test_saving_and_retreiving_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, saved_list)
        self.assertEqual(second_saved_item.text, "Item the second")
        self.assertEqual(second_saved_item.list, saved_list)
Пример #52
0
 def test_default_text(self):
     '''тест заданного по умолчанию текста'''
     item = Item()
     self.assertEqual(item.text, '')
 def test_item_str(self):
     item = Item(text='hello')
     self.assertEqual(str(item), 'hello')
Пример #54
0
 def test_default_item_text(self):
     first_item = Item()
     self.assertEqual(first_item.text, '')
 def test_default_value(self):
     item = Item()
     self.assertEqual(item.text, '')
Пример #56
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_)
Пример #57
0
 def test_string_representaion(self):
     """
     Tests the string representation of list items
     """
     item = Item(text='some text')
     self.assertEqual(str(item), 'some text')
 def test_can_have_duplicate_items_in_different_lists(self):
     list_ = List.objects.create()
     list2_ = List.objects.create()
     item = Item(list=list_, text='dup')
     item_2 = Item(list=list2_, text='dup')
     item.full_clean()  # should not raise an error
Пример #59
0
 def test_default_text(self):
     """ 
     tests that the default item text is ''
     """
     item = Item()
     self.assertEqual(item.text, '')
Пример #60
0
    def test_saving_and_retrieving_items(self):
        """ 测试待办事项正常保存 """
        list_ = List()
        list_.save()

        first_item = Item()
        first_item.text = 'one item'
        first_item.list = list_
        first_item.save()

        second_item = Item()
        second_item.text = 'two 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, 'one item')
        self.assertEqual(first_saved_item.list, list_)
        self.assertEqual(second_saved_item.text, 'two item')
        self.assertEqual(second_saved_item.list, list_)