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.
This commit is contained in:
Athanasius 2022-08-18 17:23:08 +01:00
parent 76251cfd30
commit ddf9f3524f
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62

View File

@ -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.")