Ejemplo n.º 1
0
    def test_ccs_record_mother_case_availing_services_has_phone_number(self):
        with _with_case(self.domain, 'person', datetime.utcnow()) as mother:
            with _with_case(self.domain, 'ccs_record',
                            datetime.utcnow()) as ccs_record:
                set_parent_case(self.domain,
                                ccs_record,
                                mother,
                                identifier='parent')
                self.assertFalse(
                    ccs_record_mother_case_availing_services_has_phone_number(
                        ccs_record, datetime.utcnow()))

                # refresh case to avoid cache fetch for parent
                ccs_record = CaseAccessors(self.domain).get_case(
                    ccs_record.case_id)
                self._set_case_props(mother,
                                     {'contact_phone_number': '9999999999'})
                self.assertTrue(
                    ccs_record_mother_case_availing_services_has_phone_number(
                        ccs_record, datetime.utcnow()))

                # refresh case to avoid cache fetch for parent
                ccs_record = CaseAccessors(self.domain).get_case(
                    ccs_record.case_id)
                self._set_case_props(mother, {'migration_status': 'migrated'})
                self.assertFalse(
                    ccs_record_mother_case_availing_services_has_phone_number(
                        ccs_record, datetime.utcnow()))
    def test_child_health_case_that_is_availing_services(self):
        rule = _create_empty_rule(self.domain, case_type='child_health')
        rule.add_criteria(
            CustomMatchDefinition,
            name='ICDS_CHILD_HEALTH_CASE_CHILD_AVAILING_SERVICES')

        with _with_case(self.domain, 'person', datetime.utcnow()) as child:
            with _with_case(self.domain, 'child_health',
                            datetime.utcnow()) as child_health:
                set_parent_case(self.domain,
                                child_health,
                                child,
                                relationship='extension')
                self._set_case_props(child,
                                     {"registered_status": "registered"})
                self._set_case_props(child,
                                     {"migration_status": "not_migrated"})
                self.assertTrue(
                    rule.criteria_match(child_health, datetime.utcnow()))

        with _with_case(self.domain, 'person', datetime.utcnow()) as child:
            with _with_case(self.domain, 'child_health',
                            datetime.utcnow()) as child_health:
                self._set_case_props(child,
                                     {"registered_status": "not_registered"})
                self._set_case_props(child,
                                     {"migration_status": "not_migrated"})
                set_parent_case(self.domain,
                                child_health,
                                child,
                                relationship='extension')
                self.assertFalse(
                    rule.criteria_match(child_health, datetime.utcnow()))
Ejemplo n.º 3
0
    def test_child_health_case_that_is_availing_services(self):
        with _with_case(self.domain, 'person', datetime.utcnow()) as child:
            with _with_case(self.domain, 'child_health',
                            datetime.utcnow()) as child_health:
                set_parent_case(self.domain,
                                child_health,
                                child,
                                relationship='extension')
                self._set_case_props(child,
                                     {"registered_status": "registered"})
                self._set_case_props(child,
                                     {"migration_status": "not_migrated"})
                self.assertTrue(
                    child_health_case_is_availing_services(
                        child_health, datetime.utcnow()))

        with _with_case(self.domain, 'person', datetime.utcnow()) as child:
            with _with_case(self.domain, 'child_health',
                            datetime.utcnow()) as child_health:
                self._set_case_props(child,
                                     {"registered_status": "not_registered"})
                self._set_case_props(child,
                                     {"migration_status": "not_migrated"})
                set_parent_case(self.domain,
                                child_health,
                                child,
                                relationship='extension')
                self.assertFalse(
                    child_health_case_is_availing_services(
                        child_health, datetime.utcnow()))
Ejemplo n.º 4
0
            case = self._set_case_props(case, {"add": add})
            (self.assertTrue if match else self.assertFalse)(
                rule.criteria_match(case, now),
                "%s case with add=%s should%s match" % (
                    case.type,
                    add,
                    "" if match else " not",
                ))

        now = datetime(2020, 1, 13, 12, 0)
        with _with_case(self.domain, 'person', datetime.utcnow()) as mother:
            check(mother, '2020-01-01', False)
            with _with_case(self.domain, 'person', datetime.utcnow()) as child:
                self._set_case_props(child, {"dob": '2020-01-01'})
                set_parent_case(self.domain,
                                child,
                                mother,
                                identifier='mother')
                with _with_case(self.domain, 'ccs_record',
                                datetime.utcnow()) as ccs:
                    set_parent_case(self.domain,
                                    ccs,
                                    mother,
                                    identifier='parent')
                    for match, add in [
                        (False, None),  # not set
                        (False, '2020-01-02'),  # no match
                        (True, '2020-01-01'),  # match
                    ]:
                        check(ccs, add, match)