Esempio n. 1
0
    def test_all_case_forms_deleted(self):
        from corehq.apps.callcenter.utils import sync_user_case
        sync_user_case(self.commcare_user, USERCASE_TYPE,
                       self.commcare_user.get_id)

        user_case_id = self.commcare_user.get_usercase_id()

        # other user submits form against the case (should get deleted)
        caseblock = CaseBlock(
            create=False,
            case_id=user_case_id,
        )
        submit_case_blocks(caseblock.as_string(),
                           self.domain,
                           user_id=self.other_user._id)

        case_ids = CaseAccessors(self.domain).get_case_ids_by_owners(
            [self.commcare_user._id])
        self.assertEqual(1, len(case_ids))

        form_ids = FormAccessors(self.domain).get_form_ids_for_user(
            self.commcare_user._id)
        self.assertEqual(0, len(form_ids))

        user_case = self.commcare_user.get_usercase()
        self.assertEqual(2, len(user_case.xform_ids))

        self.commcare_user.retire()

        for form_id in user_case.xform_ids:
            self.assertTrue(
                FormAccessors(self.domain).get_form(form_id).is_deleted)

        self.assertTrue(
            CaseAccessors(self.domain).get_case(user_case_id).is_deleted)
Esempio n. 2
0
    def test_multiple_case_blocks_some_deleted(self, rebuild_case):
        """ Don't rebuild deleted cases """

        case_ids = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex]

        for i, case_id in enumerate(case_ids):
            if i == 0:
                # only the first case is owned by the user getting retired
                owner_id = self.other_user._id
            else:
                owner_id = self.commcare_user._id

            caseblock = CaseBlock(
                create=True,
                case_id=case_id,
                owner_id=owner_id,
                user_id=self.commcare_user._id,
            )
            submit_case_blocks(caseblock.as_string(), self.domain, user_id=self.other_user._id)

        self.other_user.retire()

        detail = UserArchivedRebuild(user_id=self.other_user.user_id)
        expected_call_args = [mock.call(self.domain, case_id, detail) for case_id in case_ids[1:]]

        self.assertEqual(rebuild_case.call_count, len(case_ids) - 1)
        self.assertItemsEqual(rebuild_case.call_args_list, expected_call_args)
Esempio n. 3
0
    def test_forms_touching_live_case_not_deleted(self):
        case_id = uuid.uuid4().hex
        caseblock = CaseBlock(
            create=True,
            case_id=case_id,
            owner_id=self.commcare_user._id,
            user_id=self.commcare_user._id,
        )
        xform, _ = submit_case_blocks(caseblock.as_string().decode('utf-8'), self.domain)

        # other user submits form against the case and another case not owned by the user
        # should NOT get deleted since this form touches a case that's still 'alive'
        double_case_xform, _ = submit_case_blocks([
            CaseBlock(
                create=False,
                case_id=case_id,
            ).as_string().decode('utf-8'),
            CaseBlock(
                create=True,
                case_id=uuid.uuid4().hex,
                owner_id=self.other_user._id,
                user_id=self.other_user._id,
            ).as_string().decode('utf-8')
        ], self.domain, user_id=self.other_user._id)

        self.commcare_user.retire()

        self.assertTrue(FormAccessors(self.domain).get_form(xform.form_id).is_deleted)
        self.assertFalse(FormAccessors(self.domain).get_form(double_case_xform.form_id).is_deleted)

        # When the other user is deleted then the form should get deleted since it no-longer touches
        # any 'live' cases.
        self.other_user.retire()
        self.assertTrue(FormAccessors(self.domain).get_form(double_case_xform.form_id).is_deleted)
Esempio n. 4
0
    def test_multiple_case_blocks_some_deleted(self, rebuild_case):
        """ Don't rebuild deleted cases """

        case_ids = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex]

        for i, case_id in enumerate(case_ids):
            if i == 0:
                # only the first case is owned by the user getting retired
                owner_id = self.other_user._id
            else:
                owner_id = self.commcare_user._id

            caseblock = CaseBlock(
                create=True,
                case_id=case_id,
                owner_id=owner_id,
                user_id=self.commcare_user._id,
            )
            submit_case_blocks(caseblock.as_string(),
                               self.domain,
                               user_id=self.other_user._id)

        self.other_user.retire()

        detail = UserArchivedRebuild(user_id=self.other_user.user_id)
        expected_call_args = [
            mock.call(self.domain, case_id, detail) for case_id in case_ids[1:]
        ]

        self.assertEqual(rebuild_case.call_count, len(case_ids) - 1)
        self.assertItemsEqual(rebuild_case.call_args_list, expected_call_args)
Esempio n. 5
0
    def test_all_case_forms_deleted(self):
        from corehq.apps.callcenter.sync_user_case import sync_usercase
        sync_usercase(self.commcare_user)

        user_case_id = self.commcare_user.get_usercase_id()

        # other user submits form against the case (should get deleted)
        caseblock = CaseBlock(
            create=False,
            case_id=user_case_id,
        )
        submit_case_blocks(caseblock.as_string().decode('utf-8'), self.domain, user_id=self.other_user._id)

        case_ids = CaseAccessors(self.domain).get_case_ids_by_owners([self.commcare_user._id])
        self.assertEqual(1, len(case_ids))

        form_ids = FormAccessors(self.domain).get_form_ids_for_user(self.commcare_user._id)
        self.assertEqual(0, len(form_ids))

        user_case = self.commcare_user.get_usercase()
        self.assertEqual(2, len(user_case.xform_ids))

        self.commcare_user.retire()

        for form_id in user_case.xform_ids:
            self.assertTrue(FormAccessors(self.domain).get_form(form_id).is_deleted)

        self.assertTrue(CaseAccessors(self.domain).get_case(user_case_id).is_deleted)
Esempio n. 6
0
    def test_edit_an_error(self):
        form_id = uuid.uuid4().hex
        case_block = CaseBlock(
            create=True,
            case_id='',  # this should cause the submission to error
            case_type='person',
            owner_id='some-owner',
        )

        form, _ = submit_case_blocks(case_block.as_string(), domain=self.domain, form_id=form_id)
        self.assertTrue(form.is_error)
        self.assertTrue('IllegalCaseId' in form.problem)

        case_block.case_id = uuid.uuid4().hex
        form, _ = submit_case_blocks(case_block.as_string(), domain=self.domain, form_id=form_id)
        self.assertFalse(form.is_error)
        self.assertEqual(None, getattr(form, 'problem', None))
Esempio n. 7
0
    def test_edit_an_error(self):
        form_id = uuid.uuid4().hex
        case_block = CaseBlock(
            create=True,
            case_id='',  # this should cause the submission to error
            case_type='person',
            owner_id='some-owner',
        )

        form, _ = submit_case_blocks(case_block.as_string(), domain=self.domain, form_id=form_id)
        self.assertTrue(form.is_error)
        self.assertTrue('IllegalCaseId' in form.problem)

        case_block.case_id = uuid.uuid4().hex
        form, _ = submit_case_blocks(case_block.as_string(), domain=self.domain, form_id=form_id)
        self.assertFalse(form.is_error)
        self.assertEqual(None, getattr(form, 'problem', None))
 def setUp(self):
     self.domain = 'domain'
     create_domain(self.domain)
     case_type = "case"
     self.case_id = uuid.uuid4().hex
     submit_case_blocks(CaseBlock(
         self.case_id, case_type=case_type, create=True).as_string(), self.domain
     )
     caseblock1 = CaseBlock(
         self.case_id,
         case_type=case_type,
         update={'property_1': 'updated'},
     )
     caseblock2 = CaseBlock(
         self.case_id,
         case_type=case_type,
         update={'property_2': 'updated'},
     )
     blocks = [caseblock1.as_string(), caseblock2.as_string()]
     submit_case_blocks(blocks, self.domain)
Esempio n. 9
0
    def test_forms_touching_live_case_not_deleted(self):
        case_id = uuid.uuid4().hex
        caseblock = CaseBlock(
            create=True,
            case_id=case_id,
            owner_id=self.commcare_user._id,
            user_id=self.commcare_user._id,
        )
        xform, _ = submit_case_blocks(caseblock.as_string().decode('utf-8'),
                                      self.domain)

        # other user submits form against the case and another case not owned by the user
        # should NOT get deleted since this form touches a case that's still 'alive'
        double_case_xform, _ = submit_case_blocks([
            CaseBlock(
                create=False,
                case_id=case_id,
            ).as_string().decode('utf-8'),
            CaseBlock(
                create=True,
                case_id=uuid.uuid4().hex,
                owner_id=self.other_user._id,
                user_id=self.other_user._id,
            ).as_string().decode('utf-8')
        ],
                                                  self.domain,
                                                  user_id=self.other_user._id)

        self.commcare_user.retire()

        self.assertTrue(
            FormAccessors(self.domain).get_form(xform.form_id).is_deleted)
        self.assertFalse(
            FormAccessors(self.domain).get_form(
                double_case_xform.form_id).is_deleted)

        # When the other user is deleted then the form should get deleted since it no-longer touches
        # any 'live' cases.
        self.other_user.retire()
        self.assertTrue(
            FormAccessors(self.domain).get_form(
                double_case_xform.form_id).is_deleted)