def test_child_age_over_5_years(self): """ test that form is not accepted with child age greater than 5 years """ child_name = 'a' dob = '2000-05-05' form_data = {'childName': child_name, 'dob': dob} form = AddChildForm(data=form_data) self.assertFalse(form.is_valid())
def test_is_accepted(self): """ test that form is accepted with correct data format """ child_name = 'Bob' dob = '2016-05-05' form_data = {'childName': child_name, 'dob': dob} form = AddChildForm(data=form_data) self.assertTrue(form.is_valid())
def test_blank_data(self): """ test form is not valid with blank data """ form = AddChildForm({}) self.assertFalse(form.is_valid()) self.assertEqual( form.errors, { 'childName': ['This field is required.'], 'dob': ['This field is required.'], })
def test_child_name_over_100_char(self): """ test that form is not accepted with child name greater than 100 chars """ child_name = 'a' * 101 dob = '2016-05-05' form_data = {'childName': child_name, 'dob': dob} form = AddChildForm(data=form_data) self.assertFalse(form.is_valid()) self.assertEqual( form.errors, { 'childName': ['Ensure this value has at most 100 characters (it has 101).'], })
def test_dob_is_required(self): """ test that form is not valid if dob is not given """ child_name = 'Bob' form_data = {'childName': child_name} form = AddChildForm(data=form_data) self.assertFalse(form.is_valid())
def test_child_name_is_required(self): """ test that form is not valid if child name is not given """ dob = '2016-05-05' form_data = {'dob': dob} form = AddChildForm(data=form_data) self.assertFalse(form.is_valid())
def test_dob_field_label(self): """ test label shown by form for dob is correct """ form = AddChildForm() self.assertTrue(form.fields['dob'].label == 'Child Date of Birth')
def test_name_field_label(self): """ test label shown by form for childname is correct """ form = AddChildForm() self.assertTrue(form.fields['childName'].label == 'Child Name')