From bee5fc4b6a161093666c7e57f0b13ae7c59ce5a7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 29 Aug 2022 17:22:33 +0100 Subject: [PATCH] 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. --- src/tests/conftest.py | 13 ++----------- src/tests/gateway/test_get_decompressed_message.py | 2 +- src/tests/gateway/test_handle_upload.py | 8 ++++---- src/tests/gateway/test_parse_and_error_handle.py | 12 ++++++------ src/tests/gateway/test_post_upload.py | 2 +- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 7f8d0e5..36ebcb7 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -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.""" diff --git a/src/tests/gateway/test_get_decompressed_message.py b/src/tests/gateway/test_get_decompressed_message.py index e3d2f35..0deee7e 100644 --- a/src/tests/gateway/test_get_decompressed_message.py +++ b/src/tests/gateway/test_get_decompressed_message.py @@ -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( { diff --git a/src/tests/gateway/test_handle_upload.py b/src/tests/gateway/test_handle_upload.py index ea272f7..a1a99be 100644 --- a/src/tests/gateway/test_handle_upload.py +++ b/src/tests/gateway/test_handle_upload.py @@ -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" diff --git a/src/tests/gateway/test_parse_and_error_handle.py b/src/tests/gateway/test_parse_and_error_handle.py index 85d622b..0cf16e8 100644 --- a/src/tests/gateway/test_parse_and_error_handle.py +++ b/src/tests/gateway/test_parse_and_error_handle.py @@ -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: []") -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" diff --git a/src/tests/gateway/test_post_upload.py b/src/tests/gateway/test_post_upload.py index fa33413..fe4b7da 100644 --- a/src/tests/gateway/test_post_upload.py +++ b/src/tests/gateway/test_post_upload.py @@ -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' },