Example #1
0
    def test_profile_get_related_cases(self):
        total_parent_cases = 50

        id_list = ['case_id_{}'.format(i) for i in range(total_parent_cases)]
        self._createCaseStubs(
            id_list,
            user_id=self.user.user_id,
            owner_id=self.shared_group._id
        )

        new_case_ids = []
        caseblocks = []
        for i, parent_case_id in enumerate(id_list):
            case_id = 'case_id_referral_{}'.format(i)
            new_case_ids.append(case_id)
            caseblocks.append(CaseBlock(
                create=True,
                case_id=case_id,
                user_id=self.user.user_id,
                owner_id=self.referral_group._id,
                case_type=REFERRAL_TYPE,
                index={'parent': (PARENT_TYPE, parent_case_id)}
            ).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.sync_log.get_id)

        all_cases = id_list + new_case_ids
        assert_user_has_cases(self, self.referral_user, all_cases, restore_id=self.referral_sync_log.get_id)
Example #2
0
    def test_profile_get_related_cases(self):
        total_parent_cases = 50

        id_list = ['case_id_{}'.format(i) for i in range(total_parent_cases)]
        self._createCaseStubs(id_list,
                              user_id=self.user.user_id,
                              owner_id=self.shared_group._id)

        new_case_ids = []
        caseblocks = []
        for i, parent_case_id in enumerate(id_list):
            case_id = 'case_id_referral_{}'.format(i)
            new_case_ids.append(case_id)
            caseblocks.append(
                CaseBlock(create=True,
                          case_id=case_id,
                          user_id=self.user.user_id,
                          owner_id=self.referral_group._id,
                          case_type=REFERRAL_TYPE,
                          index={
                              'parent': (PARENT_TYPE, parent_case_id)
                          }).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.sync_log.get_id)

        all_cases = id_list + new_case_ids
        assert_user_has_cases(self,
                              self.referral_user,
                              all_cases,
                              restore_id=self.referral_sync_log.get_id)
 def test(self):
     if skip:
         self.skipTest(skip)
     self.build_case_structures(test_name)
     desired_cases = self._get_test(test_name).get('outcome', [])
     undesired_cases = [case for case in self.ALL_CASES if case not in desired_cases]
     sync_log = get_properly_wrapped_sync_log(self.sync_log._id)
     self.assertEqual(sync_log.case_ids_on_phone, set(desired_cases))
     assert_user_has_cases(self, self.user, desired_cases)
     assert_user_doesnt_have_cases(self, self.user, undesired_cases)
Example #4
0
    def test_profile_get_related_cases_grandparent(self):
        total_parent_cases = 5

        parent_cases = [
            'case_id_{}'.format(i) for i in range(total_parent_cases)
        ]
        self._createCaseStubs(parent_cases,
                              user_id=USER_ID,
                              owner_id=SHARED_ID)

        child_cases = []
        caseblocks = []
        for i, parent_case_id in enumerate(parent_cases):
            case_id = 'case_id_child_{}'.format(i)
            child_cases.append(case_id)
            caseblocks.append(
                CaseBlock(create=True,
                          case_id=case_id,
                          user_id=USER_ID,
                          owner_id=SHARED_ID,
                          case_type='child',
                          version=V2,
                          index={
                              'parent': (PARENT_TYPE, parent_case_id)
                          }).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.sync_log.get_id)

        referreal_cases = []
        caseblocks = []
        for i, child_case_id in enumerate(child_cases):
            case_id = 'case_id_referral_{}'.format(i)
            referreal_cases.append(case_id)
            caseblocks.append(
                CaseBlock(create=True,
                          case_id=case_id,
                          user_id=USER_ID,
                          owner_id=REFERRED_TO_GROUP,
                          case_type=REFERRAL_TYPE,
                          version=V2,
                          index={
                              'parent': ('child', child_case_id)
                          }).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.sync_log.get_id)

        all_cases = parent_cases + child_cases + referreal_cases
        assert_user_has_cases(self,
                              self.referral_user,
                              all_cases,
                              restore_id=self.referral_sync_log.get_id)
Example #5
0
    def test(self):
        if skip:
            self.skipTest(skip)
        self.build_case_structures(test_name)
        desired_cases = self._get_test(test_name).get('outcome', [])
        undesired_cases = [
            case for case in self.ALL_CASES if case not in desired_cases
        ]
        sync_log = get_properly_wrapped_sync_log(self.sync_log._id)
        self.assertEqual(sync_log.case_ids_on_phone, set(desired_cases))
        assert_user_has_cases(self, self.user, desired_cases)
        assert_user_doesnt_have_cases(self, self.user, undesired_cases)

    test.__name__ = get_test_name(test_name)
    return test
Example #6
0
    def test_multiple_batches_restore(self):
        case_ids = ["case_{}".format(i) for i in range(10)]
        self._createCaseStubs(case_ids, owner_id=USER_ID)

        restore_config, _ = assert_user_has_cases(self, self.user, case_ids)
        self.assertEqual(
            restore_config.restore_state.provider_log['num_case_batches'], 4)
Example #7
0
    def test_profile_filter_cases_modified_elsewhere_since_sync(self):
        total_cases = 100
        proportion_modified = 0

        modified = total_cases * proportion_modified
        id_list = ['case_id_{}'.format(i) for i in range(total_cases)]
        self._createCaseStubs(id_list, user_id=USER_ID, owner_id=SHARED_ID)

        caseblocks = []
        for case_id in id_list[:modified]:
            caseblocks.append(CaseBlock(
                case_id=case_id,
                user_id=OTHER_USER_ID,
                update={'favorite_color': 'blue'}
            ).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.other_sync_log.get_id)

        assert_user_has_cases(self, self.user, id_list[:modified], restore_id=self.sync_log.get_id)
    def test_profile_get_related_cases_grandparent(self):
        total_parent_cases = 5

        parent_cases = ['case_id_{}'.format(i) for i in range(total_parent_cases)]
        self._createCaseStubs(parent_cases, user_id=USER_ID, owner_id=SHARED_ID)

        child_cases = []
        caseblocks = []
        for i, parent_case_id in enumerate(parent_cases):
            case_id = 'case_id_child_{}'.format(i)
            child_cases.append(case_id)
            caseblocks.append(CaseBlock(
                create=True,
                case_id=case_id,
                user_id=USER_ID,
                owner_id=SHARED_ID,
                case_type='child',
                version=V2,
                index={'parent': (PARENT_TYPE, parent_case_id)}
            ).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.sync_log.get_id)

        referreal_cases = []
        caseblocks = []
        for i, child_case_id in enumerate(child_cases):
            case_id = 'case_id_referral_{}'.format(i)
            referreal_cases.append(case_id)
            caseblocks.append(CaseBlock(
                create=True,
                case_id=case_id,
                user_id=USER_ID,
                owner_id=REFERRED_TO_GROUP,
                case_type=REFERRAL_TYPE,
                version=V2,
                index={'parent': ('child', child_case_id)}
            ).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.sync_log.get_id)

        all_cases = parent_cases + child_cases + referreal_cases
        assert_user_has_cases(self, self.referral_user, all_cases, restore_id=self.referral_sync_log.get_id)
Example #9
0
    def test_profile_filter_cases_modified_elsewhere_since_sync(self):
        total_cases = 100
        proportion_modified = 0

        modified = total_cases * proportion_modified
        id_list = ['case_id_{}'.format(i) for i in range(total_cases)]
        self._createCaseStubs(id_list, user_id=USER_ID, owner_id=SHARED_ID)

        caseblocks = []
        for case_id in id_list[:modified]:
            caseblocks.append(
                CaseBlock(case_id=case_id,
                          user_id=OTHER_USER_ID,
                          version=V2,
                          update={
                              'favorite_color': 'blue'
                          }).as_xml())
        self._postFakeWithSyncToken(caseblocks, self.other_sync_log.get_id)

        assert_user_has_cases(self,
                              self.user,
                              id_list[:modified],
                              restore_id=self.sync_log.get_id)
Example #10
0
    def test_multiple_batches_restore(self):
        case_ids = ["case_{}".format(i) for i in range(10)]
        self._createCaseStubs(case_ids, owner_id=USER_ID)

        restore_config, _ = assert_user_has_cases(self, self.user, case_ids)
        self.assertEqual(restore_config.num_batches, 4)