def test_relationships(self):
        self.assertEqual(
            child_health_case_from_tasks_case(self.child_tasks_case).case_id,
            self.child_health_case.case_id)

        self.assertEqual(
            ccs_record_case_from_tasks_case(self.mother_tasks_case).case_id,
            self.ccs_record_case.case_id)

        self.assertEqual(
            child_person_case_from_child_health_case(
                self.child_health_case).case_id,
            self.child_person_case.case_id)

        self.assertEqual(
            mother_person_case_from_child_person_case(
                self.child_person_case).case_id,
            self.mother_person_case.case_id)

        self.assertEqual(
            mother_person_case_from_ccs_record_case(
                self.ccs_record_case).case_id, self.mother_person_case.case_id)

        self.assertEqual(
            mother_person_case_from_child_health_case(
                self.child_health_case).case_id,
            self.mother_person_case.case_id)

        self.assertEqual(
            child_person_case_from_tasks_case(self.child_tasks_case).case_id,
            self.child_person_case.case_id)
    def test_relationships(self):
        self.assertEqual(
            child_health_case_from_tasks_case(self.child_tasks_case).case_id,
            self.child_health_case.case_id
        )

        self.assertEqual(
            ccs_record_case_from_tasks_case(self.mother_tasks_case).case_id,
            self.ccs_record_case.case_id
        )

        self.assertEqual(
            child_person_case_from_child_health_case(self.child_health_case).case_id,
            self.child_person_case.case_id
        )

        self.assertEqual(
            mother_person_case_from_child_person_case(self.child_person_case).case_id,
            self.mother_person_case.case_id
        )

        self.assertEqual(
            mother_person_case_from_ccs_record_case(self.ccs_record_case).case_id,
            self.mother_person_case.case_id
        )

        self.assertEqual(
            mother_person_case_from_child_health_case(self.child_health_case).case_id,
            self.mother_person_case.case_id
        )

        self.assertEqual(
            child_person_case_from_tasks_case(self.child_tasks_case).case_id,
            self.child_person_case.case_id
        )
    def test_no_parent_case(self):
        with self.assertRaises(CaseRelationshipError):
            child_health_case_from_tasks_case(self.lone_child_tasks_case)

        with self.assertRaises(CaseRelationshipError):
            ccs_record_case_from_tasks_case(self.lone_mother_tasks_case)

        with self.assertRaises(CaseRelationshipError):
            child_person_case_from_child_health_case(
                self.lone_child_health_case)

        with self.assertRaises(CaseRelationshipError):
            mother_person_case_from_child_person_case(
                self.lone_child_person_case)

        with self.assertRaises(CaseRelationshipError):
            mother_person_case_from_ccs_record_case(self.lone_ccs_record_case)
    def test_no_parent_case(self):
        with self.assertRaises(CaseRelationshipError):
            child_health_case_from_tasks_case(self.lone_child_tasks_case)

        with self.assertRaises(CaseRelationshipError):
            ccs_record_case_from_tasks_case(self.lone_mother_tasks_case)

        with self.assertRaises(CaseRelationshipError):
            child_person_case_from_child_health_case(self.lone_child_health_case)

        with self.assertRaises(CaseRelationshipError) as raises:
            mother_person_case_from_child_person_case(self.lone_child_person_case)

        self.assertTrue(skip_notifying_missing_mother_person_case(raises.exception))

        with self.assertRaises(CaseRelationshipError):
            mother_person_case_from_ccs_record_case(self.lone_ccs_record_case)
    def test_no_parent_case(self):
        with self.assertRaises(CaseRelationshipError):
            child_health_case_from_tasks_case(self.lone_child_tasks_case)

        with self.assertRaises(CaseRelationshipError):
            ccs_record_case_from_tasks_case(self.lone_mother_tasks_case)

        with self.assertRaises(CaseRelationshipError):
            child_person_case_from_child_health_case(
                self.lone_child_health_case)

        with self.assertRaises(CaseRelationshipError) as raises:
            mother_person_case_from_child_person_case(
                self.lone_child_person_case)

        self.assertTrue(
            skip_notifying_missing_mother_person_case(raises.exception))

        with self.assertRaises(CaseRelationshipError):
            mother_person_case_from_ccs_record_case(self.lone_ccs_record_case)
Exemplo n.º 6
0
def static_negative_growth_indicator(recipient, schedule_instance):
    if schedule_instance.case.get_case_property('zscore_grading_wfa') == 'red':
        # If the child currently has a red score, do not send this message.
        # We check this here instead of checking it as part of the rule criteria
        # because if we checked it in the rule critiera, then the message would
        # send as soon as the score becomes yellow which we don't want. We just
        # want to skip sending it if it's red at the time this message is supposed
        # to send.
        return []

    form = get_last_growth_monitoring_form(schedule_instance.domain, schedule_instance.case_id)
    if not form:
        return []

    try:
        child_person_case = child_person_case_from_child_health_case(schedule_instance.case)
    except CaseRelationshipError as e:
        return notify_exception_and_return_empty_list(e)

    try:
        weight_prev = Decimal(form.form_data.get('weight_prev'))
    except (InvalidOperation, TypeError) as e:
        return notify_exception_and_return_empty_list(e)

    try:
        weight_child = Decimal(form.form_data.get('weight_child'))
    except (InvalidOperation, TypeError) as e:
        return notify_exception_and_return_empty_list(e)

    if weight_child > weight_prev:
        return []
    elif weight_child == weight_prev:
        template = 'beneficiary_static_growth.txt'
    else:
        # weight_child < weight_prev
        template = 'beneficiary_negative_growth.txt'

    language_code = recipient.get_language_code() or DEFAULT_LANGUAGE
    context = {'child_name': child_person_case.name}
    return [render_message(language_code, template, context)]