def test_invalid_cases(self): """Invalid cases shouldn't be triggered """ person = get_person_case_structure(self.person_id, self.user.user_id) occurrence = get_occurrence_case_structure(self.occurrence_id, person) episode_structure = get_episode_case_structure(self.episode_id, occurrence) self.factory.create_or_update_case(episode_structure) archived_person = get_person_case_structure("person_2", self.user.user_id, owner_id="_archive_") occurrence = get_occurrence_case_structure('occurrence_2', archived_person) invalid_episode_structure = get_episode_case_structure('episode_2', occurrence) self.factory.create_or_update_case(invalid_episode_structure) closed_person = get_person_case_structure("person_3", self.user.user_id) occurrence = get_occurrence_case_structure('occurrence_3', closed_person) closed_episode_structure = get_episode_case_structure('episode_3', occurrence) self.factory.create_or_update_case(closed_episode_structure) self.factory.create_or_update_case(CaseStructure( case_id="person_3", attrs={'close': True} )) case_ids = [ item for batch in self.case_updater._get_case_id_batches() for item in batch ] episode_ids = [episode.case_id for episode in self.case_updater._get_open_episode_cases(case_ids)] self.assertEqual(episode_ids, [self.episode_id])
def _create_episode_case( self, adherence_schedule_date_start=None, adherence_schedule_id=None, extra_properties=None, ): person = get_person_case_structure( self.person_id, self.user.user_id, ) occurrence = get_occurrence_case_structure(self.occurrence_id, person) extra_update = { 'adherence_schedule_date_start': adherence_schedule_date_start, 'adherence_schedule_id': adherence_schedule_id } extra_update.update(extra_properties or {}) episode_structure = get_episode_case_structure( self.episode_id, occurrence, extra_update=extra_update, ) cases = { case.case_id: case for case in self.factory.create_or_update_cases( [episode_structure]) }
def _get_person_structure(self, person_id, owner_id): person_fields = {ENROLLED_IN_PRIVATE: ""} person = get_person_case_structure(person_id, owner_id, extra_update=person_fields) person.attrs['owner_id'] = owner_id person.attrs['update'].update({ 'person_id': 'person_id', 'phi_area': 'phi_area', 'date_referred_out': 'date_referred_out', 'referred_by_id': 'referred_by_id', 'phone_number': '1234567890', }) return person
class BETSBeneficiaryRepeaterTest(ENikshayRepeaterTestBase): def setUp(self): super(BETSBeneficiaryRepeaterTest, self).setUp() self.domain_obj = Domain(name=self.domain) self.domain_obj.save() self.repeater = BETSBeneficiaryRepeater( domain=self.domain, url='super-cool-url', ) self.repeater.save() loc_type = LocationType.objects.create( domain=self.domain, name="loc_type", administrative=True, ) self.real_location = SQLLocation.objects.create( domain=self.domain, name="real_location", site_code="real_location", location_type=loc_type, metadata={ 'is_test': 'no', 'nikshay_code': 'nikshay_code' }, ) self.test_location = SQLLocation.objects.create( domain=self.domain, name="test_location", site_code="test_location", location_type=loc_type, metadata={ 'is_test': 'yes', 'nikshay_code': 'nikshay_code' }, ) def tearDown(self): super(BETSBeneficiaryRepeaterTest, self).tearDown() self.domain_obj.delete() def create_person_case(self, location_id, private=True): case = get_person_case_structure(None, self.episode_id) case.attrs['owner_id'] = location_id case.attrs['update']['current_episode_type'] = 'confirmed_tb' case.attrs['update']['contact_phone_number'] = '911234567890' case.attrs['update'][ ENROLLED_IN_PRIVATE] = "true" if private else "false" return self.factory.create_or_update_cases([case])[0]
def _setup_casedata(cls): cls.episode_id = "episode" factory = CaseFactory(domain=cls.domain) person = get_person_case_structure( "person", cls.user.user_id, ) occurrence = get_occurrence_case_structure("occurence", person) episode_structure = get_episode_case_structure(cls.episode_id, occurrence) cases = { case.case_id: case for case in factory.create_or_update_cases([episode_structure]) }