def test_form_validator_relation_male(self): defaults = dict(household_structure=self.household_structure) cleaned_data = dict(relation='wife', gender=MALE, **defaults) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember()) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('relation', form_validator._errors)
def test_form_validator_enrollment_checklist_complete_raises(self): cleaned_data = dict(household_structure=self.household_structure) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember(id=uuid4(), enrollment_checklist_completed=True)) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('enrollment_checklist_completed', form_validator._error_codes)
def test_form_validator_log_entry(self): """Asserts raises on missing log entry for now. Note, for tests today is set in the past, see member_helper.get_utcnow. """ cleaned_data = dict(household_structure=self.household_structure) form_validator = HouseholdMemberFormValidator( today_datetime=get_utcnow(), # set to actual today, e.g future cleaned_data=cleaned_data, instance=HouseholdMember()) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('household_log_entry', form_validator._error_codes)
def test_form_validator_initials(self): defaults = dict( household_structure=self.household_structure, relation='husband', gender=MALE, ) cleaned_data = dict(first_name='ERIK', initials='XX', **defaults) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember()) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('initials', form_validator._errors)
def test_form_validator_refused_enumeration(self): """Asserts raises if current household log entry log status is refused enumeration. """ obj = self.household_structure.householdlog.householdlogentry_set.all( ).last() obj.household_status = REFUSED_ENUMERATION obj.save() cleaned_data = dict(household_structure=self.household_structure) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember()) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('refused_enumeration', form_validator._error_codes)
def test_household_member_alive1(self): defaults = dict(household_structure=self.household_structure, first_name='ERIK', initials='EX', relation='husband', gender=MALE) cleaned_data = dict(survival_status=ALIVE, present_today=NOT_APPLICABLE, **defaults) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember()) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('present_today', form_validator._errors)
def test_household_member_alive4(self): defaults = dict(household_structure=self.household_structure, first_name='ERIK', initials='EX', gender=MALE) cleaned_data = dict(survival_status=ALIVE, present_today=YES, inability_to_participate=ABLE_TO_PARTICIPATE, study_resident=YES, relation=NOT_APPLICABLE, **defaults) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember()) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('relation', form_validator._errors)
def test_household_member_dead_but_present(self): defaults = dict(household_structure=self.household_structure, first_name='ERIK', initials='EX', gender=MALE, inability_to_participate=ABLE_TO_PARTICIPATE, study_resident=YES, personal_details_changed=NO, details_change_reason=None, age_in_years=18, relation='husband') cleaned_data = dict(survival_status=DEAD, present_today=YES, **defaults) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember(id=uuid4(), eligible_hoh=True)) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('present_today', form_validator._errors)
def test_household_member_age_in_years_and_hoh(self): defaults = dict( household_structure=self.household_structure, first_name='ERIK', initials='EX', gender=MALE, survival_status=ALIVE, present_today=YES, inability_to_participate=ABLE_TO_PARTICIPATE, study_resident=YES, personal_details_changed=NO, details_change_reason=None, ) cleaned_data = dict(age_in_years=15, relation=HEAD_OF_HOUSEHOLD, **defaults) form_validator = HouseholdMemberFormValidator( today_datetime=self.today_datetime, cleaned_data=cleaned_data, instance=HouseholdMember()) self.assertRaises(forms.ValidationError, form_validator.validate) self.assertIn('age_in_years', form_validator._errors)