def test_unborn_children_ineligible(self): self.assertFalse( get_child_eligibility_for_study(self.unborn_child, self.almost_one_study)) self.assertFalse( get_child_eligibility_for_study(self.unborn_child, self.elementary_study)) self.assertFalse( get_child_eligibility_for_study(self.unborn_child, self.teenager_study))
def test_age_range_bounds(self): for study in [ self.almost_one_study, self.elementary_study, self.teenager_study, ]: lower_bound = float(study.min_age_years * 365 + study.min_age_months * 30 + study.min_age_days) upper_bound = float(study.max_age_years * 365 + study.max_age_months * 30 + study.max_age_days) self.assertFalse( get_child_eligibility_for_study( G( Child, birthday=datetime.date.today() - datetime.timedelta(days=lower_bound - 1), ), study, ), "Child just below lower age bound is eligible", ) self.assertTrue( get_child_eligibility_for_study( G( Child, birthday=datetime.date.today() - datetime.timedelta(days=lower_bound), ), study, ), "Child at lower age bound is not eligible", ) self.assertTrue( get_child_eligibility_for_study( G( Child, birthday=datetime.date.today() - datetime.timedelta(days=upper_bound), ), study, ), f"Child at upper age bound ({upper_bound} days) is not eligible", ) self.assertFalse( get_child_eligibility_for_study( G( Child, birthday=datetime.date.today() - datetime.timedelta(days=upper_bound + 1), ), study, ), "Child just above upper age bound is eligible", )
def test_criteria_expression_used(self): self.assertTrue( get_child_eligibility_for_study( self.twin_preemie_3yo, self.preschooler_study_with_criteria_and_age_range, )) self.assertFalse( get_child_eligibility_for_study( self.twin_full_term_3yo, self.preschooler_study_with_criteria_and_age_range, ))
def _validated(deserialized_groups): """Yield only groups with targets that satisfy criteria for their respective studies.""" for user, child_study_pairs in deserialized_groups: valid_message_targets = [] for pair in child_study_pairs: child, study = pair eligible = get_child_eligibility_for_study(child, study) if eligible: valid_message_targets.append(pair) if valid_message_targets: yield user, valid_message_targets
def child_is_valid_for_study(child, study): return get_child_eligibility_for_study(child, study)