def test_not_born_yet(self): tomorrow = (now() + timedelta(hours=24)).date() citizen = CitizenFactory(birth_date=tomorrow) data = model_to_dict(citizen) data = stringize(data) form = CitizenRecordForm(data) self.assertFalse(form.is_valid()) self.assertIn('birth_date', form.errors)
def test_wrong_gender_for_national_id(self): citizen = CitizenFactory( gender=FEMALE, national_id=123456789012, # expecting male gender ) data = model_to_dict(citizen) data = stringize(data) form = CitizenRecordForm(data) self.assertFalse(form.is_valid()) self.assertIn("does not match gender", str(form.errors))
def line_to_dictionary(line): """ Given a VALUES line from the input, return a dictionary with all the field values, nicely cleaned up and converted to the right data types. :param line: A VALUES line from the input :raises ValueError: if any inputs are not valie :return: a dictionary """ data = dict(zip(FIELD_NAMES, break_line(line))) form = CitizenRecordForm(data=data) if not form.is_valid(): raise ValueError(form.errors) return form.cleaned_data
def test_simple(self): citizen = CitizenFactory() data = model_to_dict(citizen) data = stringize(data) form = CitizenRecordForm(data) self.assertTrue(form.is_valid(), msg="Form errors: %r" % form.errors)