def test_patch_missing_case_with_index(self): self.submit_form(make_test_form("form-1", case_id="case-1")) case = CaseAccessorCouch.get_case("case-1") case.indices = [ CommCareCaseIndex.wrap({ "doc_type": "CommCareCaseIndex", "identifier": "parent", "referenced_type": "household", "referenced_id": "a53346d5", "relationship": "child", }) ] case.save() FormAccessors(self.domain_name).soft_delete_forms(['form-1'], datetime.utcnow(), 'test-deletion') self.do_migration(diffs=IGNORE) self.compare_diffs(changes=[ Diff('case-1', 'missing', ['*'], old='*', new=MISSING, reason="deleted forms"), ]) self.do_case_patch() self.compare_diffs() self.assert_patched_cases(["case-1"])
def reverse_indices(db, case): return db.view( "case/related", key=[case.domain, case._id, "reverse_index"], reduce=False, wrapper=lambda r: CommCareCaseIndex.wrap(r["value"]), ).all()
def indices(self): diffs = [d for d in self.diffs if d.path[0] == "indices"] if not diffs: return for diff in diffs: if diff.path != ["indices", "[*]"] or diff.new_value is not MISSING: raise CannotPatch([diff]) yield CommCareCaseIndex.wrap(diff.old_value)
def reverse_indices(db, case, wrap=True): kwargs = { 'wrapper': lambda r: CommCareCaseIndex.wrap(r['value']) if wrap else r['value'] } return db.view( "case/related", key=[case['domain'], case['_id'], "reverse_index"], reduce=False, **kwargs ).all()
def test_patch_case_index(self): self.submit_form(make_test_form("form-1", case_id="case-1")) self.do_migration(case_diff="none") index = { "doc_type": "CommCareCaseIndex", "identifier": "parent", "referenced_type": "household", "referenced_id": "a53346d5", "relationship": "child", } with self.augmented_couch_case("case-1") as case: case.indices = [CommCareCaseIndex.wrap(index)] case.save() self.do_case_diffs()
def indices(self): diffs = [d for d in self.diffs if d.path[0] == "indices"] if not diffs: return for diff in diffs: if diff.path != ["indices", "[*]"]: raise CannotPatch([diff]) if diff.new_value is MISSING and isinstance(diff.old_value, dict): yield CommCareCaseIndex.wrap(diff.old_value) elif diff.old_value is MISSING and isinstance(diff.new_value, dict): yield CommCareCaseIndex( identifier=diff.new_value["identifier"], referenced_type="", ) else: raise CannotPatch([diff])
def indices(self): from casexml.apps.case.sharedmodels import CommCareCaseIndex return [CommCareCaseIndex.wrap(index) for index in self._data['indices']]
def indices(self): from casexml.apps.case.sharedmodels import CommCareCaseIndex return [ CommCareCaseIndex.wrap(index) for index in self._data['indices'] ]
def get_reverse_indices(case): return [ CommCareCaseIndex.wrap(raw) for raw in get_reverse_indices_json(case) ]
def get_reverse_indices_for_case_id(domain, case_id): return [ CommCareCaseIndex.wrap(raw) for raw in get_reverse_indices_json(domain, case_id) ]
def get_reverse_indices_for_case_id(domain, case_id): return [CommCareCaseIndex.wrap(raw) for raw in get_reverse_indices_json(domain, case_id)]
def get_reverse_indices(case): return [CommCareCaseIndex.wrap(raw) for raw in get_reverse_indices_json(case)]
def wrap_row(row): index = CommCareCaseIndex.wrap(row['value']) index.is_reverse = True return index
def reverse_indices(db, case): return db.view("case/related", key=[case.domain, case._id, "reverse_index"], reduce=False, wrapper=lambda r: CommCareCaseIndex.wrap(r['value'])).all()