Exemple #1
0
    def test_legacy_support_toggle(self):
        restore_config = RestoreConfig(self.project, restore_user=self.user)
        factory = CaseFactory(domain=self.project.name,
                              case_defaults={'owner_id': self.user_id})
        # create a parent and child case (with index) from one user
        parent_id, child_id = [uuid.uuid4().hex for i in range(2)]
        factory.create_or_update_cases([
            CaseStructure(
                case_id=child_id,
                attrs={'create': True},
                indices=[
                    CaseIndex(
                        CaseStructure(case_id=parent_id,
                                      attrs={'create': True}),
                        relationship='child',
                        related_type='parent',
                    )
                ],
            )
        ])
        restore_payload = restore_config.get_payload().as_string().decode(
            'utf-8')
        self.assertTrue(child_id in restore_payload)
        self.assertTrue(parent_id in restore_payload)
        sync_log = deprecated_synclog_from_restore_payload(restore_payload)
        self.assertEqual(SimplifiedSyncLog, type(sync_log))
        # make both cases irrelevant by changing the owner ids
        factory.create_or_update_cases([
            CaseStructure(case_id=parent_id, attrs={'owner_id': 'different'}),
            CaseStructure(case_id=child_id, attrs={'owner_id': 'different'}),
        ],
                                       form_extras={
                                           'last_sync_token': sync_log._id
                                       })

        # doing it again should fail since they are no longer relevant

        # todo: add this back in when we add the assertion back. see SimplifiedSyncLog.prune_case
        # with self.assertRaises(SimplifiedSyncAssertionError):
        #     factory.create_or_update_cases([
        #         CaseStructure(case_id=child_id, attrs={'owner_id': 'different'}),
        #         CaseStructure(case_id=parent_id, attrs={'owner_id': 'different'}),
        #     ], form_extras={'last_sync_token': sync_log._id})

        # enabling the toggle should prevent the failure the second time
        # though we also need to hackily set the request object in the threadlocals
        LEGACY_SYNC_SUPPORT.set(self.domain, True, namespace=NAMESPACE_DOMAIN)
        request = JsonObject(domain=self.domain, path='testsubmit')
        set_request(request)
        factory.create_or_update_cases([
            CaseStructure(case_id=child_id, attrs={'owner_id': 'different'}),
            CaseStructure(case_id=parent_id, attrs={'owner_id': 'different'}),
        ],
                                       form_extras={
                                           'last_sync_token': sync_log._id
                                       })
Exemple #2
0
    def test_legacy_support_toggle(self):
        restore_config = RestoreConfig(self.project, user=self.user)
        factory = CaseFactory(domain=self.project.name, case_defaults={"owner_id": self.user_id})
        # create a parent and child case (with index) from one user
        parent_id, child_id = [uuid.uuid4().hex for i in range(2)]
        factory.create_or_update_cases(
            [
                CaseStructure(
                    case_id=child_id,
                    attrs={"create": True},
                    indices=[
                        CaseIndex(
                            CaseStructure(case_id=parent_id, attrs={"create": True}),
                            relationship="child",
                            related_type="parent",
                        )
                    ],
                )
            ]
        )
        restore_payload = restore_config.get_payload().as_string()
        self.assertTrue(child_id in restore_payload)
        self.assertTrue(parent_id in restore_payload)
        sync_log = synclog_from_restore_payload(restore_payload)
        self.assertEqual(SimplifiedSyncLog, type(sync_log))
        # make both cases irrelevant by changing the owner ids
        factory.create_or_update_cases(
            [
                CaseStructure(case_id=parent_id, attrs={"owner_id": "different"}),
                CaseStructure(case_id=child_id, attrs={"owner_id": "different"}),
            ],
            form_extras={"last_sync_token": sync_log._id},
        )

        # doing it again should fail since they are no longer relevant

        # todo: add this back in when we add the assertion back. see SimplifiedSyncLog.prune_case
        # with self.assertRaises(SimplifiedSyncAssertionError):
        #     factory.create_or_update_cases([
        #         CaseStructure(case_id=child_id, attrs={'owner_id': 'different'}),
        #         CaseStructure(case_id=parent_id, attrs={'owner_id': 'different'}),
        #     ], form_extras={'last_sync_token': sync_log._id})

        # enabling the toggle should prevent the failure the second time
        # though we also need to hackily set the request object in the threadlocals
        LEGACY_SYNC_SUPPORT.set(self.domain, True, namespace="domain")
        request = JsonObject(domain=self.domain)
        set_request(request)
        factory.create_or_update_cases(
            [
                CaseStructure(case_id=child_id, attrs={"owner_id": "different"}),
                CaseStructure(case_id=parent_id, attrs={"owner_id": "different"}),
            ],
            form_extras={"last_sync_token": sync_log._id},
        )
 def test_get_and_set(self):
     obj = object()
     set_request(obj)
     self.assertEqual(obj, get_request())
 def test_get_domain_null(self):
     set_request(None)
     self.assertEqual(None, get_request_domain())
 def test_get_domain(self):
     domain = uuid.uuid4().hex
     request = JsonObject(domain=domain)
     set_request(request)
     self.assertEqual(domain, get_request_domain())
 def test_get_and_set(self):
     obj = object()
     set_request(obj)
     self.assertEqual(obj, get_request())
 def test_get_domain_null(self):
     set_request(None)
     self.assertEqual(None, get_request_domain())
 def test_get_domain(self):
     domain = uuid.uuid4().hex
     request = JsonObject(domain=domain)
     set_request(request)
     self.assertEqual(domain, get_request_domain())
Exemple #9
0
 def tearDownClass(cls):
     set_request(None)
     super(TestNewSyncSpecifics, cls).tearDownClass()
Exemple #10
0
 def tearDown(self):
     set_request(None)
     super(GlobalRequestTest, self).tearDown()