def test_service_utils__setup_to_send__args_are_put_into_to_send_payload(): """ Make sure arguments are actually put into the payload """ def check_payload(payload): """ This function is used to validate send payloads have the passed arguments """ if payload['args'] != PROPER_ARGS: raise RuntimeError('Payload does not have args added!!!') return RETURN_PAYLOAD imported_service = utils.import_python_file_from_cwd(SERVICE_PATH) config = {} cur_addresses = utils.get_json_from_rel_path(ADDRESSES_PATH) addresses = service_utils.setup_addresses(cur_addresses, imported_service, config) connections = service_utils.setup_service_connections( addresses, imported_service, config) to_send = service_utils.setup_to_send(connections, {}) connections['out']['out_connection_1'].send = check_payload to_send('out_connection_1', PROPER_ARGS)
def test_service_utils__setup_to_send__workflow_id_put_into_to_send_payload(): """ Make sure if a workflow id is provided it is added to the payload. """ workflow_id = uuid.uuid4() def check_payload(payload): """ This function is used to validate send payloads have the passed arguments """ assert payload['workflow_id'] == workflow_id return RETURN_PAYLOAD imported_service = utils.import_python_file_from_cwd(SERVICE_PATH) config = {} cur_addresses = utils.get_json_from_rel_path(ADDRESSES_PATH) addresses = service_utils.setup_addresses(cur_addresses, imported_service, config) connections = service_utils.setup_service_connections( addresses, imported_service, config) to_send = service_utils.setup_to_send(connections, {}, workflow_id=workflow_id, increment_id=True) connections['out']['out_connection_1'].send = check_payload to_send('out_connection_1', PROPER_ARGS)
def test_service_utils_setup_to_send__workflow_id_constant_on_to_send_calls(): """ Make sure the workflow id does not increment when "increment_id" is False. This will allow services that are in main_mode to not increment the same uuid consistently. """ workflow_id = uuid.uuid4() def check_payload(payload): """ This function is used to validate send payloads have the passed arguments """ assert payload['workflow_id'] == workflow_id return RETURN_PAYLOAD imported_service = utils.import_python_file_from_cwd(SERVICE_PATH) config = {} cur_addresses = utils.get_json_from_rel_path(ADDRESSES_PATH) addresses = service_utils.setup_addresses(cur_addresses, imported_service, config) connections = service_utils.setup_service_connections( addresses, imported_service, config) to_send = service_utils.setup_to_send(connections, {}, workflow_id=workflow_id, increment_id=False) connections['out']['out_connection_1'].send = check_payload for _ in range(4): to_send('out_connection_1', PROPER_ARGS)
def test_service_utils__setup_to_send__to_send_validates_returned_args_case(): """ Make sure that the return arguments case will also be validated. """ imported_service = utils.import_python_file_from_cwd(SERVICE_PATH) config = {} cur_addresses = utils.get_json_from_rel_path(ADDRESSES_PATH) addresses = service_utils.setup_addresses(cur_addresses, imported_service, config) connections = service_utils.setup_service_connections( addresses, imported_service, config) to_send = service_utils.setup_to_send(connections, {}) connections['out']['out_connection_1'].send = lambda payload: None with pytest.raises(ValueError): to_send('out_connection_1', PROPER_ARGS)
def test_service_utils__setup_to_send__valid_connection_output_type_for_to_send( ): """ Make sure that sending will function if the output type is a connection """ imported_service = utils.import_python_file_from_cwd(SERVICE_PATH) config = {} cur_addresses = utils.get_json_from_rel_path(ADDRESSES_PATH) addresses = service_utils.setup_addresses(cur_addresses, imported_service, config) connections = service_utils.setup_service_connections( addresses, imported_service, config) to_send = service_utils.setup_to_send(connections, {}) out_connection = connections['out']['out_connection_1'] out_connection.args_validator = lambda args: None out_connection.send = lambda payload: RETURN_PAYLOAD to_send('out_connection_1', {})
def test_service_utils__setup_to_send__to_send_returns_proper_args(): """ Make sure the to_send function properly sends arguments and gets the returned arguments back. """ imported_service = utils.import_python_file_from_cwd(SERVICE_PATH) config = {} cur_addresses = utils.get_json_from_rel_path(ADDRESSES_PATH) addresses = service_utils.setup_addresses(cur_addresses, imported_service, config) connections = service_utils.setup_service_connections( addresses, imported_service, config) to_send = service_utils.setup_to_send(connections, {}) connections['out'][ 'out_connection_1'].send = lambda payload: RETURN_PAYLOAD return_arguments = to_send('out_connection_1', PROPER_ARGS) assert return_arguments == RETURN_PAYLOAD['return_args']
def test_service_utils_setup_to_send__workflow_id_incremented_on_to_send_calls( ): """ Make sure the workflow id appends the call number increases with each to_send call. This will allow a developer to more easily debug later down the line. """ workflow_id = uuid.uuid4() call_count = 0 def check_payload(payload): """ This function is used to validate send payloads have the passed arguments """ nonlocal call_count if call_count == 0: assert payload['workflow_id'] == workflow_id else: new_workflow_id = '{}_{}'.format(workflow_id, call_count) assert payload['workflow_id'] == new_workflow_id call_count += 1 return RETURN_PAYLOAD imported_service = utils.import_python_file_from_cwd(SERVICE_PATH) config = {} cur_addresses = utils.get_json_from_rel_path(ADDRESSES_PATH) addresses = service_utils.setup_addresses(cur_addresses, imported_service, config) connections = service_utils.setup_service_connections( addresses, imported_service, config) to_send = service_utils.setup_to_send(connections, {}, workflow_id=workflow_id, increment_id=True) connections['out']['out_connection_1'].send = check_payload for _ in range(4): to_send('out_connection_1', PROPER_ARGS)