def test_blank_hrs(self): """blank/null hrs become 0""" form_data = { 'project': '2', 'hours_spent': None, } form = TimecardObjectForm(form_data) self.assertFalse(form.is_valid()) self.assertEqual(form.cleaned_data['hours_spent'], 0)
def test_general_notes_field_strips_html(self): """tests that a timecard object with a notes field that has HTML in it strips the HTML before saving.""" form_data = { 'project': '2', 'hours_spent': '40', 'notes': '<strong>This is a <em>test</em>!</strong>' } form = TimecardObjectForm(form_data) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['notes'], 'This is a test!')
def test_general_has_required_notes_field(self): """tests that a timecard object with a General entry that is missing an accompaning blank notes field is not valid""" form_data = {'project': '2', 'hours_spent': '40'} form = TimecardObjectForm(form_data) self.assertFalse(form.is_valid())
def test_add_wrong_project(self): """ Check that missing projects are rejected """ form_data = {'project': '2323', 'hours_spent': '20'} form = TimecardObjectForm(form_data) self.assertFalse(form.is_valid())
def test_add_project(self): """ Test that existing projects can be added without errors """ form_data = {'project': '1', 'hours_spent': '20'} form = TimecardObjectForm(form_data) self.assertTrue(form.is_valid())