def test_can_save_same_item_to_different_lists(self): list1 = List.objects.create() list2 = List.objects.create() Item.objects.create(list=list1, text='lorem') item = Item(list=list2, text='lorem') # shouldn't raise exception item.full_clean()
def test_get_absolute_url(self): list_ = List.objects.create() self.assertEqual(list_.get_absolute_url(), '/lists/%d/' % (list_.id,)) item = Item(list=list_, text='') with self.assertRaises(ValidationError): item.save() item.full_clean()
def view_list(request, list_id): list_ = List.objects.get(id=list_id) error = None if request.method == 'POST': try: item = Item(text=request.POST['item_text'], list=list_) item.full_clean() item.save() #return redirect('/lists/%d/' % (list_.id,)) return redirect(list_) except ValidationError: error = "You can't have an empty list item" items = Item.objects.filter(list=list_) counter = items.count() status = "oh tidak" if counter == 0: status = "yey, waktunya berlibur" elif counter < 5: status = "sibuk tapi santai" else: status = "oh tidak" return render(request, 'list.html', {'items': items, 'status':status, 'list': list_, 'error': error})
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() # peform model-level validation item.save() # save to the database
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') with self.assertRaises(ValidationError): item.full_clean() # should not raise
def test_can_save_same_item_to_different_lists(self): """AssertionError: ValidationError raised.""" list1 = List.objects.create() list2 = List.objects.create() Item.objects.create(list=list1, text='foo') item = Item(list=list2, text='foo') item.full_clean() # should not raise ValidationError
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} )
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() #에러를 발생시키지 않는다.
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()
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()
def view_list(request, list_id): komentar = '' list_ = List.objects.get(id=list_id) error = None #items = Item.objects.filter(list=list_) if Item.objects.filter(list_id=list_id).count() == 0 : komentar= 'yey, waktunya berlibur' elif Item.objects.filter(list_id=list_id).count() < 5: komentar = 'sibuk tapi santai' elif Item.objects.filter(list_id=list_id).count() >=5: komentar = 'oh tidak' if request.method == 'POST': try: #Item.objects.create(text=request.POST['item_text'], list=list_) item = Item(text=request.POST['item_text'], list=list_) item.full_clean() item.save() return redirect(list_) except ValidationError: error = "You can't have an empty list item" return render(request, 'list.html', {'list' : list_, 'error': error, 'komentar' : komentar})
def test_able_to_save_same_item_to_different_lists(self): list1 = List.objects.create() list2 = List.objects.create() Item.objects.create(list=list1, text='test') item = Item(list=list2, text='test') item.full_clean()
def test_can_save_same_item_to_different_list(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() #shouldn't raise error
def view_list(request, list_id): list_ = List.objects.get(id=list_id) error = None if request.method == 'POST': try: item = Item(text=request.POST['item_text'], list=list_) item.full_clean() item.save() return redirect(list_) except ValidationError: error = "You can't have an empty list item" comment = '' countlist = Item.objects.filter(list_id=list_.id).count() if countlist == 0 : comment = 'yey, waktunya berlibur' elif (countlist > 0) and (countlist < 5) : comment = 'sibuk tapi santai' else : comment = 'oh tidak' return render(request, 'list.html', {'list': list_, 'comment':comment, 'error':error})
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()
def test_cannot_save_empty_list_items(self): list_ = List.objects.create() item = Item(list=list_, text='') with self.assertRaises(ValidationError): # this tests if the code inside the with context # will raise a validation error item.save() item.full_clean()
def test_cannot_save_empty_list_item(self): list_ = List.objects.create() item = Item(list=list_, text='') with self.assertRaises(ValidationError): item.save() # Hack to validate Django's TextField, as full validation does not run # on model save item.full_clean()
def test_cannot_save_empty_list_items(self): list_ = List.objects.create() item = Item(list=list_, text='') with self.assertRaises(ValidationError): item.save() # we need it to run full constraint validation # against SQLite item.full_clean()
def test_can_save_same_item_to_different_lists(self): list1 = List.objects.create() Item.objects.create(text='do thing', list=list1) list2 = List.objects.create() item = Item(list=list2, text='do thing') # should not raise item.full_clean()
def test_can_save_duplicate_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 item.save() self.assertEqual(Item.objects.count(), 2)
def test_cannot_save_empty_list_items(self): new_list = List.objects.create() item = Item(list=new_list, text='') # Two ways to write the followings: # Long term way: everything in 'with' block should raise validation e with self.assertRaises(ValidationError): item.save() # Django doesn't run validation on save() item.full_clean() # to run validation
def test_same_items_can_be_saved_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') try: item.full_clean() except ValidationError: self.fail('Cannot save same item to two different lists')
def test_CAN_save_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 a ValidationError
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') try: item.full_clean() except: self.fail("Cannot add same items to different lists!")
def test_cannot_save_empty_list_items(self): list_ = List.objects.create() item = Item(list=list_, text='') # the with statement is used with "context managers", which wrap a # block of code, usually with some kind of setup, cleanup, or # error-handling code with self.assertRaises(ValidationError): item.save() item.full_clean()
def test_cannot_save_empty_list_items(self): list_ = List.objects.create() item = Item(list=list_, text='') try: item.save() item.full_clean() self.fail('The save should have raised an exception') except ValidationError: pass
def test_cannot_save_empty_list_items(self): list_ = List.objects.create() item = Item(list=list_, text='') # wraps this in a try, except statement # basically, says that the test passes if it hits the except statement with self.assertRaises(ValidationError): item.save() # Django doesn't run full validation on save, so we use this. It # will fail if we ever allow a blank text field in the model. item.full_clean()
def new_list(request): list_ = List.objects.create() item = Item(text=request.POST['item_text'], list=list_) try: item.full_clean() item.save() except ValidationError: list_.delete() error = "You can't have an empty list item" return render(request, 'home.html', {"error": error}) return redirect(list_)
def newList(request): list_ = List.objects.create() item = Item(text=request.POST.get('itemText'), list=list_) try: item.full_clean() item.save() except ValidationError: list_.delete() error = escape('清單項目不能空白') return render(request, 'lists/home.html', {'error':error}) return redirect(reverse('lists:viewList', args=(list_.id, )))
def new_list(request): new_list = List.objects.create() item = Item(text=request.POST["item_text"], list=new_list) try: item.full_clean() item.save() except ValidationError: new_list.delete() error = "You can't have an empty list item" return render(request, "home.html", {"error": error}) return redirect("/lists/%d/" % (new_list.id,))
def test_can_save_same_item_to_different_lists(self): lst = List.objects.create() lst2 = List.objects.create() Item.objects.create(list=lst, text="bla") item = Item(list=lst2, text="bla") item.full_clean() # Should not raise error
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
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()
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()
def test_dupe_items_invalid(self): alist = List.objects.create() Item.objects.create(list=alist, text="bla") item = Item(list=alist, text="bla") with self.assertRaises(ValidationError): item.full_clean()
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()
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
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()
def test_CAN_save_same_item_to_different_list(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