示例#1
0
 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"])
示例#2
0
文件: util.py 项目: dimagi/casexml
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()
示例#3
0
 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)
示例#4
0
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()
示例#5
0
 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()
示例#6
0
 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])
示例#7
0
 def indices(self):
     from casexml.apps.case.sharedmodels import CommCareCaseIndex
     return [CommCareCaseIndex.wrap(index) for index in self._data['indices']]
示例#8
0
 def indices(self):
     from casexml.apps.case.sharedmodels import CommCareCaseIndex
     return [
         CommCareCaseIndex.wrap(index) for index in self._data['indices']
     ]
示例#9
0
def get_reverse_indices(case):
    return [
        CommCareCaseIndex.wrap(raw) for raw in get_reverse_indices_json(case)
    ]
示例#10
0
def get_reverse_indices_for_case_id(domain, case_id):
    return [
        CommCareCaseIndex.wrap(raw)
        for raw in get_reverse_indices_json(domain, case_id)
    ]
示例#11
0
def get_reverse_indices_for_case_id(domain, case_id):
    return [CommCareCaseIndex.wrap(raw)
            for raw in get_reverse_indices_json(domain, case_id)]
示例#12
0
def get_reverse_indices(case):
    return [CommCareCaseIndex.wrap(raw)
            for raw in get_reverse_indices_json(case)]
示例#13
0
 def wrap_row(row):
     index = CommCareCaseIndex.wrap(row['value'])
     index.is_reverse = True
     return index
示例#14
0
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()