def next(self): """Returns the next household structure instance or None in the survey_schedule sequence.""" try: next_obj = next( SurveyScheduleIterator(model_obj=self, household=self.household)) except StopIteration: next_obj = None return next_obj
def test_clone_members_to_last_household_structure(self): for household_structure in SurveyScheduleIterator( model_obj=self.first_household_structure, household=self.household): pass clone = Clone( household=self.household, survey_schedule=household_structure.survey_schedule_object, report_datetime=household_structure.survey_schedule_object.start, model='member_clone.householdmember') self.assertEqual(clone.members.filter( survey_schedule=survey_three.field_value).count(), 3)
def test_member_next(self): """Asserts gets next member in normal 1, 2 sequence. """ internal_identifier = uuid4() for household_structure in HouseholdStructure.objects.all(): HouseholdMember.objects.create( household_structure=household_structure, internal_identifier=internal_identifier) member1 = HouseholdMember.objects.get( survey_schedule=survey_one.field_value) member2 = HouseholdMember.objects.get( survey_schedule=survey_two.field_value) member_iterator = SurveyScheduleIterator( model_obj=member1, internal_identifier=internal_identifier) self.assertEqual(next(member_iterator), member2)
def test_members_list(self): """Asserts returns None if no "next" member. """ internal_identifier = uuid4() for household_structure in HouseholdStructure.objects.all(): HouseholdMember.objects.create( household_structure=household_structure, internal_identifier=internal_identifier) member1 = HouseholdMember.objects.get( survey_schedule=survey_one.field_value) member2 = HouseholdMember.objects.get( survey_schedule=survey_two.field_value) member3 = HouseholdMember.objects.get( survey_schedule=survey_three.field_value) iterable = SurveyScheduleIterator( model_obj=member1, internal_identifier=internal_identifier) self.assertEqual(list(iterable), [member2, member3]) self.assertRaises(StopIteration, next, iterable)