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 })
class SentMessageContainer(JsonObject): # retry section # Flow should be next # try to send message -> received response with retry_after -> put to queue back # and set retry_after and set create_time retry_after = IntegerProperty(exclude_if_none=True) create_time = IntegerProperty(exclude_if_none=True) retry_count = IntegerProperty(exclude_if_none=True) message_type = StringProperty(choices=['error', 'response'], required=True) #message = ObjectProperty(MessageToProcessor, required=True) message = JsonObject(required=True)
def test_get_domain(self): domain = uuid.uuid4().hex request = JsonObject(domain=domain) set_request(request) self.assertEqual(domain, get_request_domain())
class ErrorMessage(JsonObject): error_text = StringProperty() bad_request = JsonObject()
def loadVtTable(self): try: self.jsobj = JsonObject("vttable.json") pprint.pprint(self.jsobj.dict) except Exception as e: print('Exception at loadVtTable : ' + str(e))