From ddf9f3524fc78b76edd9f9e7efe0442015d84b6a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 18 Aug 2022 17:23:08 +0100 Subject: [PATCH] tests: Gateway: parse_and_error_handle: Two tests to get started This is Athanasius feeling out how best to add tests to this ancient code. * Test that eddn.Gateway.parse_and_error_handle() returns the correct error string for: - Invalid JSON being passed in. - An outdated schema being cited. --- .../gateway/test_parse_and_error_handle.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/tests/gateway/test_parse_and_error_handle.py diff --git a/src/tests/gateway/test_parse_and_error_handle.py b/src/tests/gateway/test_parse_and_error_handle.py new file mode 100644 index 0000000..669210b --- /dev/null +++ b/src/tests/gateway/test_parse_and_error_handle.py @@ -0,0 +1,28 @@ +import os +import sys + +# Tests don't include the directory that `pytest` is run from on sys.path +sys.path.append(os.getcwd()) + +import eddn.Gateway + +def test_bad_json(): + msg = "{not real json" + res = eddn.Gateway.parse_and_error_handle(msg.encode(encoding="utf-8")) + assert res.startswith("FAIL: JSON parsing: ") + +def test_outdated_schema(): + msg = """ +{ + "$schemaRef": "http://schemas.elite-markets.net/eddn/journal/1", + "header": { + "uploaderID": "outdated schema", + "softwareName": "pytest:Gateway.parse_and_error_handle", + "softwareVersion": "v0.0.1" + }, + "message": { + } +} + """ + res = eddn.Gateway.parse_and_error_handle(msg.encode(encoding="utf-8")) + assert res.startswith("FAIL: Outdated Schema: The schema you have used is no longer supported. Please check for an updated version of your application.")