Esempio n. 1
0
    def test_deleted_indices_removed(self):
        factory = CaseFactory(
            self.domain,
            case_defaults={
                'user_id': self.commcare_user._id,
                'owner_id': self.commcare_user._id,
                'case_type': 'a-case',
                'create': True,
            },
        )
        # create a parent/child set of cases
        parent_id, child_id = [uuid.uuid4().hex for i in range(2)]
        child, parent = factory.create_or_update_case(CaseStructure(
            case_id=child_id,
            indices=[
                CaseIndex(CaseStructure(case_id=parent_id))
            ]
        ))
        # confirm the child has an index, and 1 form
        self.assertEqual(1, len(child.indices))
        self.assertEqual(parent_id, child.indices[0].referenced_id)
        self.assertEqual(1, len(child.xform_ids))

        # simulate parent deletion
        FormProcessorInterface.soft_delete_case(parent_id)

        # call the remove index task
        remove_indices_from_deleted_cases(self.domain, [parent_id])

        # check that the index is removed via a new form
        child = CommCareCase.get(child_id)
        self.assertEqual(0, len(child.indices))
        self.assertEqual(2, len(child.xform_ids))
Esempio n. 2
0
 def test_assign_bad_index_ref(self):
     # the case has to exist to create the index, but if we delete it later the assignment
     # shouldn't fail
     case = self._new_case()
     case_with_bad_ref = self._new_case(index={"parent": ("person", case._id)})
     FormProcessorInterface.soft_delete_case(case._id)
     # this call previously failed
     res = assign_case(case_with_bad_ref.id, self.primary_user._id, include_subcases=True, include_parent_cases=True)
     self.assertEqual(2, len(res))
     self.assertIn(case_with_bad_ref._id, res)
     self.assertIn(case._id, res)