def test_get_task_action(scopes, expected, raises): task = {'scopes': scopes} config = {'actions': ['submission', 'aliases']} if raises: with pytest.raises(ScriptWorkerTaskException): get_task_action(task, config) else: assert expected == get_task_action(task, config)
def test_get_task_action(scopes, expected, raises): task = {'scopes': scopes} config = { 'schema_files': { 'submission': '/some/path.json', 'aliases': '/some/other_path.json', }, } if raises: with pytest.raises(ScriptWorkerTaskException): get_task_action(task, config) else: assert expected == get_task_action(task, config)
def test_get_task_action(scopes, expected, raises): task = {"scopes": scopes} config = { "taskcluster_scope_prefix": "project:releng:bouncer:", "schema_files": { "submission": "/some/path.json", "aliases": "/some/other_path.json" } } if raises: with pytest.raises(ScriptWorkerTaskException): get_task_action(task, config) else: assert expected == get_task_action(task, config)
def test_do_failed_with_TimeoutError_api_call(submission_context, mocker, event_loop, fake_TimeoutError_throwing_session): context = submission_context context.server = get_task_server(context.task, context.config) context.action = get_task_action(context.task, context.config) context.session = fake_TimeoutError_throwing_session with pytest.raises(aiohttp.ServerTimeoutError): event_loop.run_until_complete(_do_api_call(context, "dummy", {}))
def test_do_failed_with_ClientError_api_call( context, mocker, event_loop, fake_ClientError_throwing_session): context.server = get_task_server(context.task, context.config) context.action = get_task_action(context.task, context.config) context.session = fake_ClientError_throwing_session with pytest.raises(aiohttp.ClientError): event_loop.run_until_complete(_do_api_call(context, 'dummy', {}))
def test_do_failed_api_call(submission_context, mocker, event_loop, fake_session_500): context = submission_context context.server = get_task_server(context.task, context.config) context.action = get_task_action(context.task, context.config) context.session = fake_session_500 response = event_loop.run_until_complete(_do_api_call(context, "dummy", {})) assert response == "{}"
def test_do_failed_api_call(context, mocker, event_loop, fake_session_500): context.server = get_task_server(context.task, context.config) context.action = get_task_action(context.task, context.config) context.session = fake_session_500 response = event_loop.run_until_complete(_do_api_call( context, 'dummy', {})) assert response == '{}' context.session.close()
async def async_main(context): context.task = get_task(context.config) # determine the task server and action context.server = get_task_server(context.task, context.config) context.action = get_task_action(context.task, context.config) # perform schema validation for the corresponding type of task validate_task_schema(context, action_map[context.action]['schema']) # perform the appropriate behavior await action_map[context.action]['function'](context)
async def async_main(context): # perform schema validation for the corresponding type of task validate_task_schema(context) # determine the task server and action context.server = get_task_server(context.task, context.config) context.action = get_task_action(context.task, context.config) # perform the appropriate behavior if action_map.get(context.action): await action_map[context.action](context) else: raise TaskVerificationError("Unknown action: {}!".format(context.action))
def test_do_successful_api_call(submission_context, mocker, event_loop, fake_session, data, credentials): context = submission_context context.server = get_task_server(context.task, context.config) context.action = get_task_action(context.task, context.config) context.session = fake_session if not credentials: del context.config["bouncer_config"][context.server]["username"] del context.config["bouncer_config"][context.server]["password"] with pytest.raises(KeyError): response = event_loop.run_until_complete(_do_api_call(context, "dummy", data)) return response = event_loop.run_until_complete(_do_api_call(context, "dummy", data)) assert response == "{}"