def test_custom_action(self): rule = create_empty_rule( self.domain, AutomaticUpdateRule.WORKFLOW_CASE_UPDATE, case_type="circus", ) case1 = CaseFactory(self.domain).create_case( case_type="circus", update={ "all_activity_complete_date": "2021-06-31", }, ) case2 = CaseFactory(self.domain).create_case( case_type="circus", update={ "size": "big", }, ) set_all_activity_complete_date_to_today(case1, rule) set_all_activity_complete_date_to_today(case2, rule) today = datetime.today().strftime(ISO_DATE_FORMAT) case1 = CommCareCase.objects.get_case(case1.case_id) case2 = CommCareCase.objects.get_case(case2.case_id) self.assertEqual(case1.get_case_property("all_activity_complete_date"), "2021-06-31") self.assertEqual(case2.get_case_property("all_activity_complete_date"), today) self.assertFalse(case1.closed) self.assertFalse(case2.closed)
def test_custom_action(self): checkin_case = self.make_checkin_case() rule = create_empty_rule( self.domain, AutomaticUpdateRule.WORKFLOW_CASE_UPDATE, case_type="checkin", ) case_properties = { "assigned_to_primary_checkin_case_id": checkin_case.case_id, "is_assigned_primary": "foo", "assigned_to_primary_name": "bar", "assigned_to_primary_username": "******", } patient_case = CaseFactory(self.domain).create_case( case_type="patient", owner_id=self.mobile_worker.get_id, update=case_properties, ) other_patient_case = CaseFactory(self.domain).create_case( case_type="patient", owner_id=self.mobile_worker.get_id, update={"assigned_to_primary_checkin_case_id": "123"}, ) other_case = CaseFactory(self.domain).create_case( case_type="other", owner_id=self.mobile_worker.get_id, update={"assigned_to_primary_checkin_case_id": checkin_case.case_id}, ) for case in [patient_case, other_patient_case, other_case]: send_to_elasticsearch("case_search", transform_case_for_elasticsearch(case.to_json())) self.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index) close_cases_assigned_to_checkin(checkin_case, rule) self.assertTrue(CommCareCase.objects.get_case(checkin_case.case_id).closed, self.domain) patient_case = CommCareCase.objects.get_case(patient_case.case_id, self.domain) self.assertFalse(patient_case.closed) for prop in case_properties: self.assertEqual(patient_case.get_case_property(prop), "") other_case = CommCareCase.objects.get_case(other_case.case_id, self.domain) self.assertFalse(other_case.closed) self.assertEqual( other_case.get_case_property("assigned_to_primary_checkin_case_id"), checkin_case.case_id, ) other_patient_case = CommCareCase.objects.get_case(other_patient_case.case_id, self.domain) self.assertFalse(other_patient_case.closed) self.assertEqual( other_patient_case.get_case_property("assigned_to_primary_checkin_case_id"), "123", )