def test_expense_form_valid_data(self): form = ExpenseForm(data = { 'title': 'expense1', 'amount': 1000, 'category': 'development' }) self.assertTrue(form.is_valid())
def test_form_invalid_no_data(self): form = ExpenseForm(data={}) self.assertFalse(form.is_valid()) self.assertEquals(len(form.errors), 3)
def test_empty_form(self): form = ExpenseForm(data={ 'title': '', 'amount': 2000, 'category': 'development' }) self.assertFalse(form.is_valid())
def test_form_with_correct_data(self): form = { "title": "Correct data form", "amount": 1000, "category": "correct category", } correct_form = ExpenseForm(data=form) self.assertTrue(correct_form.is_valid())
def test_form_invalid_string(self): invalid_title = "This is a long title" + "e" * 100 form = { "title": invalid_title, "amount": 1000, "category": "correct category", } invalid_form = ExpenseForm(data=form) self.assertFalse(invalid_form.is_valid()) self.assertEquals(len(invalid_form.errors), 1)
def test_expense_form_valid_data(self): form = ExpenseForm( data={"title": "expense1", "amount": 1000, "category": "development"} ) self.assertTrue(form.is_valid())
def test_expense_form_no_data(self): form = ExpenseForm(data={}) self.assertFalse(form.is_valid()) self.assertEquals(len(form.errors), 3) # one error for every empty field
def test_expense_form_invalid_data(self): #make a form form = ExpenseForm(data={}) self.assertFalse(form.is_valid()) #make sure there are 3 errors; one for every field missing self.assertEquals(len(form.errors), 3)