From 1c9828c67a0c995d4c600bfa60af76507f9953e0 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Thu, 4 Jun 2020 21:42:52 +0200 Subject: [PATCH] added a more detailed happy-flow test --- test/test_job_routes.py | 68 +++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/test/test_job_routes.py b/test/test_job_routes.py index b7ff1ddf..6e9127d1 100644 --- a/test/test_job_routes.py +++ b/test/test_job_routes.py @@ -42,6 +42,18 @@ TASK_STATUS_SCHEMA = { "items": {"$ref": "#/definitions/task"} } +TASK_LOG_SCHEMA = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "pending": {"type": "array", "items": {"type": "string"}}, + "errors": {"type": "array", "items": {"type": "string"}}, + "failed": {"type": "array", "items": {"type": "string"}}, + "warnings": {"type": "array", "items": {"type": "string"}}, + }, + "required": ["pending", "errors", "failed", "warnings"], + "additionalProperties": False +} def backend_db(): return _get_redis({ @@ -260,21 +272,54 @@ def test_job_log(client): test_events = { 'joblog:AAAA:task-aaa': { - 'type': 'task-aaaa', 'uuid': 'AAAA', 'clock': 999}, + 'type': 'task-aaaa', 'uuid': 'AAAA'}, 'joblog:AAAB:task-infox': { - 'type': 'task-infox', 'uuid': 'AAAB', 'clock': 999}, + 'type': 'task-infox', 'uuid': 'AAAB'}, + + 'joblog:CCCC:task-received': { + 'type': 'task-received', 'uuid': 'CCCC', 'name': 'xyz', 'args': ['z', 1]}, + 'joblog:CCCC:task-started': { + 'type': 'task-started', 'uuid': 'CCCC'}, + 'joblog:CCCC:task-succeeded': { + 'type': 'task-succeeded', 'uuid': 'CCCC'}, + + 'joblog:TTTT:task-received': { + 'type': 'task-received', 'uuid': 'TTTT', 'name': 'xyz', 'args': ['q', 123]}, + 'joblog:TTTT:task-started': { + 'type': 'task-started', 'uuid': 'TTTT'}, + 'joblog:TTTT:task-failed': { + 'type': 'task-failed', 'uuid': 'TTTT'}, + + 'joblog:SSSS1:task-received': { + 'type': 'task-received', 'uuid': 'SSSS', 'name': 'xyz', 'args': ['q', 123]}, + 'joblog:SSSS1:task-started': { + 'type': 'task-started', 'uuid': 'SSSS'}, + 'joblog:SSSS2:task-received': { + 'type': 'task-received', 'uuid': 'SSSS2', 'name': 'xyz', 'args': ['q', 123]}, + 'joblog:SSSS2:task-started': { + 'type': 'task-started', 'uuid': 'SSSS2'}, + 'joblog:SSSS3:task-received': { + 'type': 'task-received', 'uuid': 'SSSS3', 'name': 'xyz', 'args': ['q', 123]}, + 'joblog:SSSS3:task-started': { + 'type': 'task-started', 'uuid': 'SSSS3'}, + 'joblog:BBBB:task-info:99': { - 'type': 'task-info', 'uuid': 'BBBB', 'clock': 99}, + 'type': 'task-info', 'uuid': 'BBBB', 'clock': 99, 'message': 'x'}, 'joblog:BBBB:task-info:999': { - 'type': 'task-info', 'uuid': 'BBBB', 'clock': 999}, + 'type': 'task-info', 'uuid': 'BBBB', 'clock': 999, 'message': 'x'}, + 'joblog:AAAA:task-warning:88': { - 'type': 'task-warning', 'uuid': 'AAAA', 'clock': 88}, + 'type': 'task-warning', 'uuid': 'AAAA', 'clock': 88, 'message': 'x'}, 'joblog:AAAA:task-warning:888': { - 'type': 'task-warning', 'uuid': 'AAAA', 'clock': 888}, + 'type': 'task-warning', 'uuid': 'AAAA', 'clock': 888, 'message': 'x'}, + 'joblog:AAAA:task-error:77': { - 'type': 'task-error', 'uuid': 'AAAA', 'clock': 77}, + 'type': 'task-error', 'uuid': 'AAAA', 'clock': 77, 'message': 'x'}, 'joblog:AAAA:task-error:777': { - 'type': 'task-error', 'uuid': 'AAAA', 'clock': 777} + 'type': 'task-error', 'uuid': 'AAAA', 'clock': 777, 'message': 'x'}, + 'joblog:AAAA:task-error:7777': { + 'type': 'task-error', 'uuid': 'AAAA', 'clock': 7777, 'message': 'x'} + } db = backend_db() @@ -286,4 +331,9 @@ def test_job_log(client): headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 result = json.loads(rv.data.decode('utf-8')) - assert len(result.keys()) == 3 # TODO: make a proper test + jsonschema.validate(result, TASK_LOG_SCHEMA) + + assert len(result['errors']) == 3 + assert len(result['pending']) == 3 + assert len(result['failed']) == 1 + assert len(result['warnings']) == 2 -- GitLab