def setUp(self): super().setUp() delete_all_users() self.domain_obj = create_domain(self.domain) enable_usercase(self.domain) with trap_extra_setup(ConnectionError): self.es = get_es_new() initialize_index_and_mapping(self.es, CASE_SEARCH_INDEX_INFO) username = normalize_username("mobile_worker_1", self.domain) self.mobile_worker = CommCareUser.create(self.domain, username, "123", None, None) sync_user_cases(self.mobile_worker) self.checkin_case = CaseFactory(self.domain).create_case( case_type="checkin", owner_id=self.mobile_worker.get_id, update={"username": self.mobile_worker.raw_username}, ) send_to_elasticsearch( "case_search", transform_case_for_elasticsearch(self.checkin_case.to_json())) self.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index) self.case_accessor = CaseAccessors(self.domain)
def setUpClass(cls): super(TestFilterDslLookups, cls).setUpClass() with trap_extra_setup(ConnectionError): cls.es = get_es_new() initialize_index_and_mapping(cls.es, CASE_SEARCH_INDEX_INFO) cls.child_case_id = 'margaery' cls.parent_case_id = 'mace' cls.grandparent_case_id = 'olenna' cls.domain = "Tyrell" factory = CaseFactory(domain=cls.domain) grandparent_case = CaseStructure( case_id=cls.grandparent_case_id, attrs={ 'create': True, 'case_type': 'grandparent', 'update': { "name": "Olenna", "alias": "Queen of thorns", "house": "Tyrell", }, }) parent_case = CaseStructure( case_id=cls.parent_case_id, attrs={ 'create': True, 'case_type': 'parent', 'update': { "name": "Mace", "house": "Tyrell", }, }, indices=[CaseIndex( grandparent_case, identifier='mother', relationship='child', )]) child_case = CaseStructure( case_id=cls.child_case_id, attrs={ 'create': True, 'case_type': 'child', 'update': { "name": "Margaery", "house": "Tyrell", }, }, indices=[CaseIndex( parent_case, identifier='father', relationship='extension', )], ) for case in factory.create_or_update_cases([child_case]): send_to_elasticsearch('case_search', transform_case_for_elasticsearch(case.to_json())) cls.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index)
def close_all_usercases(self): usercase_ids = CommCareCase.objects.get_case_ids_in_domain(self.domain, USERCASE_TYPE) for usercase_id in usercase_ids: CaseFactory(self.domain).close_case(usercase_id) usercase = CommCareCase.objects.get_case(usercase_id, self.domain) send_to_elasticsearch( "case_search", transform_case_for_elasticsearch(usercase.to_json()) ) self.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index)
def test_associated_usercase_closed(self): usercase_ids = self.case_accessor.get_case_ids_in_domain(type=USERCASE_TYPE) for usercase_id in usercase_ids: CaseFactory(self.domain).close_case(usercase_id) usercase = self.case_accessor.get_case(usercase_id) send_to_elasticsearch( "case_search", transform_case_for_elasticsearch(usercase.to_json()) ) self.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index) self.assertTrue(associated_user_case_closed(self.checkin_case, None))
def make_checkin_case(self, properties=None): properties = properties if properties is not None else {"username": self.mobile_worker.raw_username} checkin_case = CaseFactory(self.domain).create_case( case_type="checkin", owner_id=self.mobile_worker.get_id, update=properties, ) send_to_elasticsearch( "case_search", transform_case_for_elasticsearch(checkin_case.to_json()) ) self.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index) return checkin_case