def test_footprint_with_extension(self): """ Extensions are brought in if the host case is owned; Host case is brought in if the extension is owned """ 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)]) self.factory.create_or_update_cases([host, extension]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual(footprint_info.all_ids, set([extension.case_id, host.case_id])) self.assertEqual(footprint_info.base_ids, set([host.case_id])) footprint_info = get_case_footprint_info(self.domain, self.other_owner_id) self.assertEqual(footprint_info.all_ids, set([extension.case_id, host.case_id])) self.assertEqual(footprint_info.base_ids, set([extension.case_id]))
def _get_case_ids_for_owners_with_extensions(self, owner_id): """Fetches base and extra cases when extensions are enabled""" if not self.is_clean( owner_id) or self.restore_state.is_first_extension_sync: # If this is the first time a user with extensions has synced after # the extension flag is toggled, pull all the cases so that the # extension parameters get set correctly return get_case_footprint_info(self.restore_state.domain, owner_id).all_ids else: if self.is_new_owner(owner_id): # for a clean owner's initial sync the base set is just the open ids and their extensions all_case_ids = set( self.case_accessor.get_open_case_ids_for_owner(owner_id)) new_case_ids = set(all_case_ids) while new_case_ids: all_case_ids = all_case_ids | new_case_ids extension_case_ids = set( self.case_accessor.get_extension_case_ids( new_case_ids)) new_case_ids = extension_case_ids - all_case_ids return all_case_ids else: # for a clean owner's steady state sync, the base set is anything modified since last sync modified_non_extension_cases = set( self.case_accessor.get_case_ids_modified_with_owner_since( owner_id, self.restore_state.last_sync_log.date)) # we also need to fetch unowned extension cases that have been modified extension_case_ids = list(self.restore_state.last_sync_log. extension_index_tree.indices.keys()) modified_extension_cases = set( filter_cases_modified_since( self.case_accessor, extension_case_ids, self.restore_state.last_sync_log.date)) return modified_non_extension_cases | modified_extension_cases
def test_footprint_with_extension_of_child(self): """ Extensions of children should be included """ parent = CaseStructure(case_id=uuid.uuid4().hex, attrs={ 'owner_id': self.other_owner_id, 'create': True, 'close': True }) child = CaseStructure(case_id=uuid.uuid4().hex, attrs={ 'owner_id': self.owner_id, 'create': True }, indices=[CaseIndex(parent)]) extension = CaseStructure( case_id=uuid.uuid4().hex, attrs={ 'owner_id': self.other_owner_id, 'create': True }, indices=[CaseIndex(child, relationship=CASE_INDEX_EXTENSION)]) self.factory.create_or_update_cases([parent, child, extension]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual( footprint_info.all_ids, set([extension.case_id, parent.case_id, child.case_id]))
def _get_case_ids_for_owners_with_extensions(self, owner_id): """Fetches base and extra cases when extensions are enabled""" if not self.is_clean(owner_id) or self.restore_state.is_first_extension_sync: # If this is the first time a user with extensions has synced after # the extension flag is toggled, pull all the cases so that the # extension parameters get set correctly return get_case_footprint_info(self.restore_state.domain, owner_id).all_ids else: if self.is_new_owner(owner_id): # for a clean owner's initial sync the base set is just the open ids and their extensions all_case_ids = set(self.case_accessor.get_open_case_ids_for_owner(owner_id)) new_case_ids = set(all_case_ids) while new_case_ids: all_case_ids = all_case_ids | new_case_ids extension_case_ids = set(self.case_accessor.get_extension_case_ids(new_case_ids)) new_case_ids = extension_case_ids - all_case_ids return all_case_ids else: # for a clean owner's steady state sync, the base set is anything modified since last sync modified_non_extension_cases = set(self.case_accessor.get_case_ids_modified_with_owner_since( owner_id, self.restore_state.last_sync_log.date )) # we also need to fetch unowned extension cases that have been modified extension_case_ids = self.restore_state.last_sync_log.extension_index_tree.indices.keys() modified_extension_cases = set(filter_cases_modified_since( self.case_accessor, extension_case_ids, self.restore_state.last_sync_log.date )) return modified_non_extension_cases | modified_extension_cases
def test_cousins(self): """http://manage.dimagi.com/default.asp?189528 """ grandparent = CaseStructure(case_id="Steffon", attrs={'owner_id': self.other_owner_id}) parent_1 = CaseStructure(case_id="Stannis", attrs={'owner_id': self.other_owner_id}, indices=[CaseIndex(grandparent)]) parent_2 = CaseStructure(case_id="Robert", attrs={'owner_id': self.other_owner_id}, indices=[CaseIndex(grandparent)]) child_1 = CaseStructure(case_id="Shireen", attrs={'owner_id': self.owner_id}, indices=[CaseIndex(parent_1)]) child_2 = CaseStructure(case_id="Joffrey", attrs={'owner_id': self.owner_id}, indices=[CaseIndex(parent_2)]) self.factory.create_or_update_cases( [grandparent, parent_1, parent_2, child_1, child_2]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual( footprint_info.all_ids, set([ grandparent.case_id, parent_1.case_id, parent_2.case_id, child_1.case_id, child_2.case_id ]))
def test_simple_footprint(self): """ should only return open cases from user """ case = CaseStructure(case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id, 'create': True}) closed_case = CaseStructure(case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id, 'close': True, 'create': True}) other_case = CaseStructure(case_id=uuid.uuid4().hex, attrs={'owner_id': self.other_owner_id, 'create': True}) self.factory.create_or_update_cases([case, other_case, closed_case]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual(footprint_info.all_ids, set([case.case_id]))
def test_simple_footprint(self): """ should only return open cases from user """ case = CaseStructure(case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id}) closed_case = CaseStructure(case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id, 'close': True}) other_case = CaseStructure(case_id=uuid.uuid4().hex, attrs={'owner_id': self.other_owner_id}) self.factory.create_or_update_cases([case, other_case, closed_case]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual(footprint_info.all_ids, set([case.case_id]))
def get_case_ids_for_owner(self, owner_id): if self.is_clean(owner_id): if self.restore_state.is_initial: # for a clean owner's initial sync the base set is just the open ids return set(get_open_case_ids(self.restore_state.domain, owner_id)) else: # for a clean owner's steady state sync, the base set is anything modified since last sync return set(get_case_ids_modified_with_owner_since( self.restore_state.domain, owner_id, self.restore_state.last_sync_log.date )) else: # todo: we may want to be smarter than this # right now just return the whole footprint and do any filtering later return get_case_footprint_info(self.restore_state.domain, owner_id).all_ids
def test_footprint_with_extension(self): """ Extensions are brought in if the host case is owned; Host case is brought in if the extension is owned """ 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)] ) self.factory.create_or_update_cases([host, extension]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual(footprint_info.all_ids, set([extension.case_id, host.case_id])) self.assertEqual(footprint_info.base_ids, set([host.case_id])) footprint_info = get_case_footprint_info(self.domain, self.other_owner_id) self.assertEqual(footprint_info.all_ids, set([extension.case_id, host.case_id])) self.assertEqual(footprint_info.base_ids, set([extension.case_id]))
def _get_case_ids_for_owners_without_extensions(self, owner_id): if self.is_clean(owner_id): if self.is_new_owner(owner_id): # for a clean owner's initial sync the base set is just the open ids return set(self.case_accessor.get_open_case_ids_for_owner(owner_id)) else: # for a clean owner's steady state sync, the base set is anything modified since last sync return set(self.case_accessor.get_case_ids_modified_with_owner_since( owner_id, self.restore_state.last_sync_log.date )) else: # TODO: we may want to be smarter than this # right now just return the whole footprint and do any filtering later # Note: This will also return extensions if they exist. return get_case_footprint_info(self.restore_state.domain, owner_id).all_ids
def test_footprint_with_parent(self): """ should return open cases with parents """ parent = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.other_owner_id, 'close': True, 'create': True} ) child = CaseStructure( case_id=uuid.uuid4().hex, attrs={'owner_id': self.owner_id, 'create': True}, indices=[CaseIndex(parent)] ) self.factory.create_or_update_cases([parent, child]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual(footprint_info.all_ids, set([child.case_id, parent.case_id])) self.assertEqual(footprint_info.base_ids, set([child.case_id]))
def test_footprint_with_parent(self): """ should return open cases with parents """ 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)] ) self.factory.create_or_update_cases([parent, child]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual(footprint_info.all_ids, set([child.case_id, parent.case_id])) self.assertEqual(footprint_info.base_ids, set([child.case_id]))
def test_footprint_with_extension_of_child(self): """ Extensions of children should be included """ 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]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual(footprint_info.all_ids, set([extension.case_id, parent.case_id, child.case_id]))
def test_cousins(self): """http://manage.dimagi.com/default.asp?189528 """ grandparent = CaseStructure( case_id="Steffon", attrs={'owner_id': self.other_owner_id} ) parent_1 = CaseStructure( case_id="Stannis", attrs={'owner_id': self.other_owner_id}, indices=[CaseIndex(grandparent)] ) parent_2 = CaseStructure( case_id="Robert", attrs={'owner_id': self.other_owner_id}, indices=[CaseIndex(grandparent)] ) child_1 = CaseStructure( case_id="Shireen", attrs={'owner_id': self.owner_id}, indices=[CaseIndex(parent_1)] ) child_2 = CaseStructure( case_id="Joffrey", attrs={'owner_id': self.owner_id}, indices=[CaseIndex(parent_2)] ) self.factory.create_or_update_cases([grandparent, parent_1, parent_2, child_1, child_2]) footprint_info = get_case_footprint_info(self.domain, self.owner_id) self.assertEqual( footprint_info.all_ids, set([grandparent.case_id, parent_1.case_id, parent_2.case_id, child_1.case_id, child_2.case_id]) )