mirror of
https://github.com/EDCD/EDDN.git
synced 2025-05-05 09:31:03 +03:00
tests: Move to loading test messages from files
* Implement a new fixture `eddn_message_from_file()` for testing this. Eventually this will get renamed to `eddn_message()`. * Files containing one message each go under `tests/eddn_message`, with sub-directories for `<schema>/<version>[/<event>]` and then the filename is the nature of that file in that context. Completely invalid files, i.e. not even valid JSON, can be placed in the top level of `tests/eddn_message`. * Use this for the `parse_and_error_handle()` "valid journal/1 scan" test.
This commit is contained in:
parent
fa8952d0d5
commit
30bc05cf29
@ -1,5 +1,6 @@
|
|||||||
"""General pytest configuration, including fixtures."""
|
"""General pytest configuration, including fixtures."""
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
|
|
||||||
@ -89,6 +90,17 @@ test_messages = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def eddn_message_from_file() -> 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)
|
||||||
|
with open(path, 'r') as eddn_message:
|
||||||
|
return eddn_message.read()
|
||||||
|
|
||||||
|
return _method
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def eddn_message() -> Callable:
|
def eddn_message() -> Callable:
|
||||||
"""Supply the requested test message."""
|
"""Supply the requested test message."""
|
||||||
|
@ -26,9 +26,9 @@ def test_fail_validation_no_softwarename(fix_sys_path, eddn_gateway, eddn_messag
|
|||||||
assert res.startswith("FAIL: Schema Validation: [<ValidationError: \"'softwareName' is a required property\">]")
|
assert res.startswith("FAIL: Schema Validation: [<ValidationError: \"'softwareName' is a required property\">]")
|
||||||
|
|
||||||
|
|
||||||
def test_valid_journal_scan(fix_sys_path, eddn_gateway, eddn_message: Callable) -> None:
|
def test_valid_journal_scan(fix_sys_path, eddn_gateway, eddn_message_from_file: Callable) -> None:
|
||||||
"""Test a valid journal/1, `event == 'Scan'` message."""
|
"""Test a valid journal/1, `event == 'Scan'` message."""
|
||||||
msg = eddn_message('plain_journal_scan_valid')
|
msg = eddn_message_from_file('journal/1/scan/valid.json')
|
||||||
res = eddn_gateway.parse_and_error_handle(msg.encode(encoding="utf-8"))
|
res = eddn_gateway.parse_and_error_handle(msg.encode(encoding="utf-8"))
|
||||||
assert res == "OK"
|
assert res == "OK"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user