def test_is_usercase_of_ls(self): rule = _create_empty_rule(self.domain, case_type=USERCASE_TYPE) rule.add_criteria(CustomMatchDefinition, name='ICDS_IS_USERCASE_OF_LS') with create_user_case(self.aww) as aww_uc, create_user_case( self.ls) as ls_uc: self.assertFalse(rule.criteria_match(aww_uc, datetime.utcnow())) self.assertTrue(rule.criteria_match(ls_uc, datetime.utcnow()))
def test_agency_user_case_from_voucher_fulfilled_by_id(self): prescription = self.create_prescription_case() voucher = self.create_voucher_case(prescription.case_id) self.assertIsNone( agency_user_case_from_voucher_fulfilled_by_id( None, CaseReminder(domain=self.domain) ) ) self.assertIsNone( agency_user_case_from_voucher_fulfilled_by_id( None, CaseReminder(domain=self.domain, case_id=voucher.case_id) ) ) user = CommCareUser.create(self.domain, 'mobile', 'password') update_case(self.domain, voucher.case_id, case_properties={'voucher_fulfilled_by_id': user.get_id}) with create_user_case(user) as user_case: self.assertEqual( agency_user_case_from_voucher_fulfilled_by_id( None, CaseReminder(domain=self.domain, case_id=voucher.case_id) ).case_id, user_case.case_id )
def test_run_indicator_for_usercase(self): with create_user_case(self.user1) as case: with patch('custom.icds.messaging.custom_content.run_indicator_for_user') as patched: run_indicator_for_usercase(case, object) patched.assert_called_once() call_args = patched.call_args[0] self.assertTrue(isinstance(call_args[0], CommCareUser)) self.assertEqual(call_args[0].get_id, self.user1.get_id) self.assertEqual(call_args[1], object)
def test_run_indicator_for_usercase(self): with create_user_case(self.user1) as case: with patch('custom.icds.messaging.custom_content.run_indicator_for_user') as patched: run_indicator_for_usercase(case, object) patched.assert_called_once() call_args = patched.call_args[0] self.assertTrue(isinstance(call_args[0], CommCareUser)) self.assertEqual(call_args[0].get_id, self.user1.get_id) self.assertEqual(call_args[1], object)
def test_prescription_voucher_alert_recipients(self): located_in_mehsana.clear(self.phi) self.dto.site_code = LOCATION_SITE_CODE_MEHSANA self.dto.save() self.assign_person_to_location(self.phi.location_id) prescription = self.create_prescription_case() voucher = self.create_voucher_case(prescription.case_id) user = CommCareUser.create(self.domain, 'mobile', 'password', location=self.phi) # No user case created yet result = prescription_voucher_alert_recipients( None, CaseReminder(domain=self.domain, case_id=voucher.case_id) ) self.assertTrue(isinstance(result, CommCareCaseSQL)) self.assertEqual(result.case_id, self.person_id) # Create user case with create_user_case(user) as user_case: result = prescription_voucher_alert_recipients( None, CaseReminder(domain=self.domain, case_id=voucher.case_id) ) self.assertTrue(isinstance(result, list)) self.assertEqual( [case.case_id for case in result], [self.person_id, user_case.case_id] ) # Test location outside Mehsana located_in_mehsana.clear(self.phi) self.dto.site_code = 'dto-other' self.dto.save() result = prescription_voucher_alert_recipients( None, CaseReminder(domain=self.domain, case_id=voucher.case_id) ) self.assertTrue(isinstance(result, CommCareCaseSQL)) self.assertEqual(result.case_id, self.person_id)
def test_is_usercase_of_ls(self): with create_user_case(self.aww) as aww_uc, create_user_case( self.ls) as ls_uc: self.assertFalse(is_usercase_of_ls(aww_uc, datetime.utcnow())) self.assertTrue(is_usercase_of_ls(ls_uc, datetime.utcnow()))