Skip to content
Snippets Groups Projects
Commit 72b40ed0 authored by Erik Reid's avatar Erik Reid
Browse files

updated unit tests with new response formats

parent fe1f8fb6
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,14 @@ DEFAULT_REQUEST_HEADERS = {
"Accept": ["application/json"]
}
TASK_ID_LIST_SCHEMA = {
TASK_ID_RESPONSE_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {"type": "string"}
"type": "object",
"properties": {
"task id": {"type": "string"}
},
"required": ["task id"],
"additionalProperties": False
}
TASK_STATUS_SCHEMA = {
......@@ -22,7 +26,7 @@ TASK_STATUS_SCHEMA = {
"exception": {"type": "boolean"},
"ready": {"type": "boolean"},
"success": {"type": "boolean"},
"result": {"type": "object"}
"result": {"type": ["object", "null"]}
},
"required": ["id", "status", "exception", "ready", "success"],
"additionalProperties": False
......@@ -30,25 +34,25 @@ TASK_STATUS_SCHEMA = {
def test_job_update_all(client, mocker):
expected_task_ids = ['abc', 'def', 'xyz@123#456']
expected_task_id = 'xyz@123#456'
launch_refresh_cache_all = mocker.patch(
'inventory_provider.tasks.worker.launch_refresh_cache_all')
launch_refresh_cache_all.return_value = expected_task_ids
launch_refresh_cache_all.return_value = expected_task_id
rv = client.post(
'jobs/update',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
task_id_list = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(task_id_list, TASK_ID_LIST_SCHEMA)
assert set(task_id_list) == set(expected_task_ids)
refresh_task_response = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(refresh_task_response, TASK_ID_RESPONSE_SCHEMA)
assert refresh_task_response['task id'] == expected_task_id
def test_job_update_force_pending(client, mocker):
expected_task_ids = ['22', 'agfafg', 'asf#asdf%111', '234']
expected_task_id = 'asf#asdf%111'
launch_refresh_cache_all = mocker.patch(
'inventory_provider.tasks.worker.launch_refresh_cache_all')
launch_refresh_cache_all.return_value = expected_task_ids
launch_refresh_cache_all.return_value = expected_task_id
mocked_get_latch = mocker.patch(
'inventory_provider.routes.jobs.get_latch')
......@@ -58,9 +62,9 @@ def test_job_update_force_pending(client, mocker):
'jobs/update?force=true',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
task_id_list = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(task_id_list, TASK_ID_LIST_SCHEMA)
assert set(task_id_list) == set(expected_task_ids)
refresh_task_response = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(refresh_task_response, TASK_ID_RESPONSE_SCHEMA)
assert refresh_task_response['task id'] == expected_task_id
def test_job_update_pending_force_false(client, mocker):
......@@ -114,9 +118,9 @@ def test_reload_router_config(client, mocker):
'jobs/reload-router-config/ignored###123',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
task_id_list = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(task_id_list, TASK_ID_LIST_SCHEMA)
assert task_id_list == ['bogus task id']
refresh_task_response = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(refresh_task_response, TASK_ID_RESPONSE_SCHEMA)
assert refresh_task_response['task id'] == 'bogus task id'
def test_check_task_status_success(client, mocker):
......@@ -156,7 +160,6 @@ def test_check_task_status_custom_status(client, mocker):
assert not status['exception']
assert not status['ready']
assert not status['success']
assert 'result' not in status
def test_check_task_status_exception(client, mocker):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment