def test_children_and_extensions(self): parent = CaseStructure(case_id=uuid.uuid4().hex, attrs={ 'owner_id': self.other_owner_id, 'close': True }) child = CaseStructure(case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id}, indices=[CaseIndex(parent)]) extension = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.other_owner_id}, indices=[CaseIndex(child, relationship=CASE_INDEX_EXTENSION)]) self.factory.create_or_update_cases([parent, child, extension]) all_ids = set([parent.case_id, child.case_id, extension.case_id]) self.assertEqual( all_ids, get_dependent_case_info(self.domain, [child.case_id]).all_ids) self.assertEqual( set([]), get_dependent_case_info(self.domain, [parent.case_id]).all_ids) self.assertEqual( set([extension.case_id]), get_dependent_case_info(self.domain, [child.case_id]).extension_ids) self.assertEqual( set([]), get_dependent_case_info(self.domain, [parent.case_id]).extension_ids)
def test_returns_extension_of_extension(self): host = CaseStructure(case_id=uuid.uuid4().hex, attrs={ 'owner_id': self.owner_id, 'create': True }) extension = CaseStructure( case_id=uuid.uuid4().hex, attrs={ 'owner_id': self.other_owner_id, 'create': True }, indices=[CaseIndex(host, relationship=CASE_INDEX_EXTENSION)]) extension_2 = CaseStructure( case_id=uuid.uuid4().hex, indices=[CaseIndex(extension, relationship=CASE_INDEX_EXTENSION)], attrs={'create': True}) all_ids = set([host.case_id, extension.case_id, extension_2.case_id]) self.factory.create_or_update_cases([extension_2]) self.assertEqual( all_ids, get_dependent_case_info(self.domain, [host.case_id]).all_ids) self.assertEqual( all_ids, get_dependent_case_info(self.domain, [extension.case_id]).all_ids) self.assertEqual( all_ids, get_dependent_case_info(self.domain, [extension_2.case_id]).all_ids) self.assertEqual( set([extension.case_id, extension_2.case_id]), get_dependent_case_info(self.domain, [host.case_id]).extension_ids)
def _case_results(self, case_id_list): def _filter(res): if self.filters: for path, val in self.filters.items(): actual_val = safe_index(res.case_json, path.split("/")) if actual_val != val: # closed=false => case.closed == False if val in ('null', 'true', 'false'): if actual_val != json.loads(val): return False else: return False return True if self.filters and not self.footprint: base_results = self._populate_results(case_id_list) return list(filter(_filter, base_results)) if self.footprint: initial_case_ids = set(case_id_list) dependent_case_ids = get_dependent_case_info( self.domain, initial_case_ids).all_ids all_case_ids = initial_case_ids | dependent_case_ids else: all_case_ids = case_id_list if self.ids_only: return [ CaseAPIResult(domain=self.domain, id=case_id, id_only=True) for case_id in all_case_ids ] else: return self._populate_results(all_case_ids)
def _case_results(self, case_id_list): def _filter(res): if self.filters: for path, val in self.filters.items(): actual_val = safe_index(res.case_json, path.split("/")) if actual_val != val: # closed=false => case.closed == False if val in ('null', 'true', 'false'): if actual_val != json.loads(val): return False else: return False return True if self.filters and not self.footprint: base_results = self._populate_results(case_id_list) return filter(_filter, base_results) if self.footprint: initial_case_ids = set(case_id_list) dependent_case_ids = get_dependent_case_info(self.domain, initial_case_ids).all_ids all_case_ids = initial_case_ids | dependent_case_ids else: all_case_ids = case_id_list if self.ids_only: return [CaseAPIResult(domain=self.domain, id=case_id, id_only=True) for case_id in all_case_ids] else: return self._populate_results(all_case_ids)
def test_returns_simple_extension(self): host = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id} ) extension = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.other_owner_id}, indices=[CaseIndex(host, relationship=CASE_INDEX_EXTENSION)] ) all_ids = set([host.case_id, extension.case_id]) self.factory.create_or_update_cases([host, extension]) self.assertEqual(all_ids, get_dependent_case_info(self.domain, [host.case_id]).all_ids) self.assertEqual(all_ids, get_dependent_case_info(self.domain, [extension.case_id]).all_ids) self.assertEqual(set([extension.case_id]), get_dependent_case_info(self.domain, [host.case_id]).extension_ids)
def test_children_and_extensions(self): parent = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.other_owner_id, 'close': True} ) child = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id}, indices=[CaseIndex(parent)] ) extension = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.other_owner_id}, indices=[CaseIndex(child, relationship=CASE_INDEX_EXTENSION)] ) self.factory.create_or_update_cases([parent, child, extension]) all_ids = set([parent.case_id, child.case_id, extension.case_id]) self.assertEqual(all_ids, get_dependent_case_info(self.domain, [child.case_id]).all_ids) self.assertEqual(set([]), get_dependent_case_info(self.domain, [parent.case_id]).all_ids) self.assertEqual(set([extension.case_id]), get_dependent_case_info(self.domain, [child.case_id]).extension_ids) self.assertEqual(set([]), get_dependent_case_info(self.domain, [parent.case_id]).extension_ids)
def test_returns_nothing_with_no_dependencies(self): case = CaseStructure() self.factory.create_or_update_case(case) self.assertEqual(set(), get_dependent_case_info(self.domain, [case.case_id]).all_ids)