def deserialize(cls, data): # type: (dict) -> FlowState invocation = Invocation.deserialize(data['invocation']) operations_data = data.get('operations', {}) operations = {k: Operation.deserialize(v) for k, v in operations_data.items()} flow_error_data = data.get('error') flow_error = FlowError.deserialize(flow_error_data) if flow_error_data else None return FlowState(data['id'], data['status'], invocation, operations, flow_error)
def test_invoke_flow_missing_successors(self): with self.assertRaises(ValueError) as context: self.flow_control_service.invoke_flow_request().set_invocation( Invocation('import1')).set_flow(Flow().add_component( 'import1', Component(ComponentType.import_file, ['missing-successor-name'], import_file_specification))).execute() self.assertEqual( str(context.exception), 'Missing successor components: [\'missing-successor-name\']')
def test_invoke_flow_copy_file(self): self._register_invoke_flow_response(invoke_flow_copy_file_response) flow_state = self.flow_control_service.invoke_flow_request( ).set_invocation( Invocation(['copyfile1'], [Source('/source/path.txt')])).set_flow( Flow().add_component( 'copyfile1', Component( ComponentType.copy_file, [], CopyFileSpecification( Destination('/destination/path.txt'))))).execute() self._assert_flow(invoke_flow_copy_file_request, flow_state)
def test_invoke_flow_with_callback(self): self._register_invoke_flow_response(invoke_flow_callback_response) flow_state = self.flow_control_service.invoke_flow_request( ).set_invocation( Invocation( ['import1'], callback=Callback( 'http://requestbin.fullcontact.com/sc9kxnsc', {'attachment-key': 'attachment-value'}, {'header': 'value'}))).set_flow(Flow().add_component( 'import1', Component(ComponentType.import_file, [], import_file_specification))).execute() self._assert_flow(invoke_flow_callback_request, flow_state)
def test_invoke_flow_with_add_sources(self): self._register_invoke_flow_response( invoke_flow_with_add_sources_response) extra_metadata = AudioExtraMetadata( 'track_name', 'artist', 'album_name', 'track_number', 'genre', 'composer', 'year', Image('image_url', 'mime_type', 'image_description'), Lyrics('text', 'eng', 'lyrics_description')) flow_state = self.flow_control_service.invoke_flow_request( ).set_invocation(Invocation([ 'addSources1', 'addSources2' ], [])).set_flow(Flow().add_component( 'addSources1', Component(ComponentType.add_sources, [ 'metadata1' ], AddSourcesSpecification([ Source('/source/path.mp3') ]))).add_component( 'addSources2', Component( ComponentType.add_sources, ['metadata2' ], AddSourcesSpecification([ Source('/source/path2.mp3') ]))).add_component( 'metadata1', Component( ComponentType.replace_extra_metadata, [], ReplaceAudioExtraMetadataSpecification( Destination( '/destination/path.mp3', None, ACL.private), extra_metadata))).add_component( 'metadata2', Component( ComponentType.replace_extra_metadata, [], ReplaceAudioExtraMetadataSpecification( Destination( '/destination/path2.mp3', None, ACL.private), extra_metadata)))).execute() self._assert_flow(invoke_flow_with_add_sources_request, flow_state)
def test_invoke_flow_convert_font(self): self._register_invoke_flow_response(invoke_flow_convert_font_response) flow_state = self.flow_control_service.invoke_flow_request( ).set_invocation( Invocation(['convert-font'], [Source('/source/font.ttf')])).set_flow( Flow().add_component( 'convert-font', Component( ComponentType.convert_font, [], ConvertFontSpecification( Destination('/destination/font.woff', None, ACL.private), FontType.woff)))).execute() self._assert_flow(invoke_flow_convert_font_request, flow_state)
def test_invoke_flow1_request(self): self._register_invoke_flow_response(invoke_flow1_response) transcode_specification = TranscodeSpecification( Destination(directory='/deliverables/'), quality_range=VideoQualityRange(VideoQuality.res_720p, VideoQuality.res_1080p)) flow_state = self.flow_control_service.invoke_flow_request( ).set_invocation(Invocation(['import'])).set_flow(Flow().add_component( 'import', Component(ComponentType.import_file, ['transcode'], import_file_specification)).add_component( 'transcode', Component(ComponentType.transcode, ['playlist'], transcode_specification)).add_component( 'playlist', Component(ComponentType.playlist, []))).execute() self._assert_flow(invoke_flow1_request, flow_state)
def test_invoke_flow_with_group_wait(self): self._register_invoke_flow_response(invoke_flow_group_wait_response) flow_state = self.flow_control_service.invoke_flow_request( ).set_invocation( Invocation(['copy1', 'copy2'], [ Source('/source/path.txt') ])).set_flow(Flow().add_component( 'copy1', Component( ComponentType.copy_file, ['group-wait'], CopyFileSpecification( Destination('/destination/path1.txt')))).add_component( 'copy2', Component( ComponentType.copy_file, ['group-wait'], CopyFileSpecification( Destination('/destination/path2.txt')))). add_component('group-wait', Component(ComponentType.group_wait, []))).execute() self._assert_flow(invoke_flow_group_wait_request, flow_state)