def deserialize(cls, data): # type: (dict) -> Job sources = [Source.deserialize(source) for source in data['sources']] date_created = datetime_serialization.deserialize(data['dateCreated']) date_updated = datetime_serialization.deserialize(data['dateUpdated']) callback_data = data.get('callback') callback = Callback.deserialize( callback_data) if callback_data else None specification = data['specification'] if cls.specification_type: specification = cls.specification_type.deserialize(specification) result_data = data.get('result') if result_data: # todo: deserialize result payload as specific type result = RestResult.deserialize(result_data) else: result = None job = cls(data['id'], data['issuer'], data['status'], specification, sources, callback, data.get('flowId'), result, date_created, date_updated) job.type = data['type'] return job
def deserialize(cls, data): # type: (dict) -> FileDescriptor lifecycle_data = data.get('lifecycle') lifecycle = Lifecycle.deserialize( lifecycle_data) if lifecycle_data else None return FileDescriptor( data['path'], data['id'], data['type'], data['mimeType'], data['size'], data['acl'], lifecycle, data.get('hash'), datetime_serialization.deserialize(data.get('dateCreated')), datetime_serialization.deserialize(data.get('dateUpdated')))
'specification': { 'source': source.serialize(), 'destination': destination.serialize(), 'extractedFilesReport': { 'destination': destination.serialize(), 'format': 'json' } }, 'groupId': 'group-id', 'flowId': None, 'dateUpdated': '2001-12-25T00:00:00Z', 'type': 'urn:job:archive.extract', 'callback': None } frozen_time = datetime_serialization.deserialize('2001-12-25T00:00:00Z') extraction_report = ExtractionReport(destination, ExtractionReportFormat.json) specification = ExtractArchiveSpecification(source, destination, extraction_report) job = ExtractArchiveJob('group-id_job-key', 'urn:member:xxx', 'pending', specification, [source], date_created=frozen_time, date_updated=frozen_time) class TestJob(TestCase): def test_serialize(self): serialized = job.serialize()
def test_deserialize(self): time_string = '2002-12-25T00:00:00Z' time = datetime_serialization.deserialize(time_string) assert_that(time, is_(datetime(2002, 12, 25)))