mirror of
https://github.com/EDCD/EDDN.git
synced 2025-05-06 18:11:04 +03:00
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:
parent
30bc05cf29
commit
bee5fc4b6a
@ -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."""
|
||||
|
@ -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(
|
||||
{
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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'
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user