tests: Convert all existing tests to from-file eddn_message

* The "testing" `eddn_message_from_file()` got renamed to, and replaced,
  `eddn_message()`.
* All of the tests were updated to use this new form of the fixture.
* Next commit will add the directory containing those test files.
This commit is contained in:
Athanasius 2022-08-29 17:22:33 +01:00
parent 30bc05cf29
commit bee5fc4b6a
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62
5 changed files with 14 additions and 23 deletions

View File

@ -91,25 +91,16 @@ test_messages = {
@pytest.fixture()
def eddn_message_from_file() -> Callable:
def eddn_message() -> Callable:
"""Load and supply a test message from the on-disk collection."""
def _method(msg_type: str) -> Optional[str]:
path = pathlib.Path('tests/eddn_message/' + msg_type)
path = pathlib.Path('tests/eddn_message/' + msg_type + '.json')
with open(path, 'r') as eddn_message:
return eddn_message.read()
return _method
@pytest.fixture
def eddn_message() -> Callable:
"""Supply the requested test message."""
def _method(msg_type: str) -> Optional[str]:
return test_messages.get(msg_type)
return _method
@pytest.fixture
def fix_sys_path() -> None:
"""Set up an eddn.Gateway import."""

View File

@ -13,7 +13,7 @@ def test_plain_message(eddn_message: Callable, monkeypatch) -> None:
eddn.Gateway.setup_bottle_app()
print(f'{eddn.Gateway.app.__dict__=}')
msg = eddn_message('plain_journal_scan_valid')
msg = eddn_message('journal/1/scan/valid')
dc_msg = eddn.Gateway.get_decompressed_message(
{

View File

@ -16,7 +16,7 @@ def test_valid_plain_message(
status: int = 200
####################################################################
msg = eddn_message("plain_journal_scan_valid")
msg = eddn_message("journal/1/scan/valid")
resp_str = eddn_gateway.handle_upload(
headers={
"Content-Type": "application/json"
@ -43,7 +43,7 @@ def test_invalid_message(
status: int = 200
####################################################################
msg = eddn_message("invalid_json")
msg = eddn_message("invalid/invalid-JSON")
resp_str = eddn_gateway.handle_upload(
headers={
"Content-Type": "application/json"
@ -70,7 +70,7 @@ def test_outdated_schema(
status: int = 200
####################################################################
msg = eddn_message("plain_outdated_schema")
msg = eddn_message("invalid/invalid-outdated-schema")
resp_str = eddn_gateway.handle_upload(
headers={
"Content-Type": "application/json"
@ -97,7 +97,7 @@ def test_no_softwarename(
status: int = 200
####################################################################
msg = eddn_message("plain_no_softwarename")
msg = eddn_message("invalid/scan-invalid-no-softwarename")
resp_str = eddn_gateway.handle_upload(
headers={
"Content-Type": "application/json"

View File

@ -4,14 +4,14 @@ from typing import Callable
def test_invalid_json(fix_sys_path, eddn_gateway, eddn_message: Callable) -> None:
"""Test invalid JSON input."""
msg = eddn_message('invalid_json')
msg = eddn_message('invalid/invalid-JSON')
res = eddn_gateway.parse_and_error_handle(msg.encode(encoding="utf-8"))
assert res.startswith("FAIL: JSON parsing: ")
def test_outdated_schema(fix_sys_path, eddn_gateway, eddn_message: Callable) -> None:
"""Test attempt to use an outdated schema."""
msg = eddn_message('plain_outdated_schema')
msg = eddn_message('invalid/invalid-outdated-schema')
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."
@ -21,20 +21,20 @@ def test_outdated_schema(fix_sys_path, eddn_gateway, eddn_message: Callable) ->
def test_fail_validation_no_softwarename(fix_sys_path, eddn_gateway, eddn_message: Callable) -> None:
"""Test detecting a message with no softwareName in the message."""
msg = eddn_message('plain_no_softwarename')
msg = eddn_message('invalid/scan-invalid-no-softwarename')
res = eddn_gateway.parse_and_error_handle(msg.encode(encoding="utf-8"))
assert res.startswith("FAIL: Schema Validation: [<ValidationError: \"'softwareName' is a required property\">]")
def test_valid_journal_scan(fix_sys_path, eddn_gateway, eddn_message_from_file: Callable) -> None:
def test_valid_journal_scan(fix_sys_path, eddn_gateway, eddn_message: Callable) -> None:
"""Test a valid journal/1, `event == 'Scan'` message."""
msg = eddn_message_from_file('journal/1/scan/valid.json')
msg = msg = eddn_message('journal/1/scan/valid')
res = eddn_gateway.parse_and_error_handle(msg.encode(encoding="utf-8"))
assert res == "OK"
def test_valid_commodity(fix_sys_path, eddn_gateway, eddn_message: Callable) -> None:
"""Test a valid commodity/3 message."""
msg = eddn_message('plain_commodity_valid')
msg = eddn_message('commodity/3/valid-smallest-message')
res = eddn_gateway.parse_and_error_handle(msg.encode(encoding="utf-8"))
assert res == "OK"

View File

@ -21,7 +21,7 @@ def test_plain_message(eddn_message: Callable) -> None:
dc_msg = test_app.post(
'/upload/',
params=eddn_message('plain_journal_scan_valid'),
params=eddn_message('journal/1/scan/valid'),
headers={
'Content-Type': 'application/json'
},