diff --git a/pyproject.toml b/pyproject.toml index d5f9e2efeac8776d325b98a0ce727762d403e973..99627a66183656a1fbb927f932c5c07c4a1f1b54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ exclude = ''' [tool.mypy] exclude = [ "venv", - "test/*", "docs" ] ignore_missing_imports = true diff --git a/test/conftest.py b/test/conftest.py index 5083af8bf9bf6ebdaa5c7d14a5934227440a8ae4..bc4781a512dfbf09bca43571853eed69eb5ac783 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,6 +1,7 @@ import json import os import tempfile +from typing import Any, Generator import pytest from fastapi.testclient import TestClient @@ -11,13 +12,13 @@ TEST_CONFIG = {"collection-name": "kvklink.echo", "test-role": "kvklink.echo.ech @pytest.fixture -def config_data(): +def config_data() -> dict[str, str]: """Start the server with valid configuration data.""" return {"ansible_playbooks_root_dir": "/"} @pytest.fixture -def config_file(config_data): +def config_file(config_data: dict[str, str]) -> Generator[str, Any, None]: """Fixture that will yield a filename that contains a valid configuration. :return: Path to valid configuration file @@ -29,7 +30,7 @@ def config_file(config_data): @pytest.fixture -def client(config_file): +def client(config_file: str) -> Generator[TestClient, Any, None]: """Return a client that can be used to test the server.""" os.environ["SETTINGS_FILENAME"] = config_file app = lso.create_app() diff --git a/test/routes/__init__.py b/test/routes/__init__.py index b9b2d1be9ffc139ab201226b98fdd6891d635868..b1490578a4f0cb8871454268461cb9c9b582878b 100644 --- a/test/routes/__init__.py +++ b/test/routes/__init__.py @@ -1,13 +1,15 @@ from io import StringIO +from typing import Any TEST_CALLBACK_URL = "https://fqdn.abc.xyz/api/resume" -def test_ansible_runner_run(**kwargs): - class Runner: - def __init__(self): - self.status = "success" - self.rc = 0 - self.stdout = StringIO("some initial text data") +class Runner: + def __init__(self) -> None: + self.status = "success" + self.rc = 0 + self.stdout = StringIO("[{'step one': 'results'}, {'step two': 2}]") + +def test_ansible_runner_run(**kwargs: Any) -> Runner: return Runner() diff --git a/test/routes/test_device.py b/test/routes/test_device.py index e42172d54567210d763050cf5170456ea337267c..63fb7c73883a5025e9dd4f40a251788e995e8c03 100644 --- a/test/routes/test_device.py +++ b/test/routes/test_device.py @@ -3,13 +3,14 @@ from unittest.mock import patch import jsonschema import responses +from starlette.testclient import TestClient from lso.playbook import PlaybookLaunchResponse from test.routes import TEST_CALLBACK_URL, test_ansible_runner_run @responses.activate -def test_router_provisioning(client): +def test_router_provisioning(client: TestClient) -> None: responses.put(url=TEST_CALLBACK_URL, status=204) params = { @@ -43,7 +44,7 @@ def test_router_provisioning(client): # wait two seconds for the run thread to finish time.sleep(2) - jsonschema.validate(response, PlaybookLaunchResponse.schema()) + jsonschema.validate(response, PlaybookLaunchResponse.model_json_schema()) responses.assert_call_count(TEST_CALLBACK_URL, 1) assert response["status"] == "ok" diff --git a/test/routes/test_ip_trunk.py b/test/routes/test_ip_trunk.py index bd44e1d9609c1e5d197f7f5bdd648dbc64443cab..af0037520ddde5959ed9839c801ce626c987d25c 100644 --- a/test/routes/test_ip_trunk.py +++ b/test/routes/test_ip_trunk.py @@ -3,6 +3,7 @@ from unittest.mock import patch import jsonschema import responses +from starlette.testclient import TestClient from lso.playbook import PlaybookLaunchResponse from test.routes import TEST_CALLBACK_URL, test_ansible_runner_run @@ -91,7 +92,7 @@ _SUBSCRIPTION_OBJECT = { @responses.activate -def test_ip_trunk_provisioning(client): +def test_ip_trunk_provisioning(client: TestClient) -> None: responses.put(url=TEST_CALLBACK_URL, status=204) params = { @@ -109,14 +110,14 @@ def test_ip_trunk_provisioning(client): # wait a second for the run thread to finish time.sleep(1) - jsonschema.validate(response, PlaybookLaunchResponse.schema()) + jsonschema.validate(response, PlaybookLaunchResponse.model_json_schema()) responses.assert_call_count(TEST_CALLBACK_URL, 1) assert response["status"] == "ok" @responses.activate -def test_ip_trunk_modification(client): +def test_ip_trunk_modification(client: TestClient) -> None: responses.put(url=TEST_CALLBACK_URL, status=204) params = { @@ -134,14 +135,14 @@ def test_ip_trunk_modification(client): # wait a second for the run thread to finish time.sleep(1) - jsonschema.validate(response, PlaybookLaunchResponse.schema()) + jsonschema.validate(response, PlaybookLaunchResponse.model_json_schema()) responses.assert_call_count(TEST_CALLBACK_URL, 1) assert response["status"] == "ok" @responses.activate -def test_ip_trunk_deletion(client): +def test_ip_trunk_deletion(client: TestClient) -> None: responses.put(url=TEST_CALLBACK_URL, status=204) params = {"callback": TEST_CALLBACK_URL, "dry_run": True, "verb": "terminate", "subscription": _SUBSCRIPTION_OBJECT} @@ -153,7 +154,7 @@ def test_ip_trunk_deletion(client): # wait a second for the run thread to finish time.sleep(1) - jsonschema.validate(response, PlaybookLaunchResponse.schema()) + jsonschema.validate(response, PlaybookLaunchResponse.model_json_schema()) responses.assert_call_count(TEST_CALLBACK_URL, 1) assert response["status"] == "ok" diff --git a/test/test_config.py b/test/test_config.py index 60836be7f0055548d6e12b61e0310dea31766906..83a47d172bc486495a85900a56a25c73941020e7 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -9,7 +9,7 @@ import pytest from lso import config -def test_validate_testenv_config(config_file): +def test_validate_testenv_config(config_file: str) -> None: """Load a configuration from a file. :param config_file: Configuration file pytest fixture @@ -22,7 +22,7 @@ def test_validate_testenv_config(config_file): @pytest.mark.parametrize( "bad_config", [{"name": "bad version", "version": 123}, {"name": "missing version"}, {"version": "missing name"}] ) -def test_bad_config(bad_config): +def test_bad_config(bad_config: dict) -> None: with io.StringIO(json.dumps(bad_config)) as file: file.seek(0) # rewind file position to the beginning with pytest.raises(jsonschema.ValidationError): diff --git a/tox.ini b/tox.ini index ec1dbc51dbeb6383da63d9e736f239f70c5480a0..3563a2ee0498be5192a1eb990b94c40fc145b760 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,5 @@ [flake8] -ignore = D100,D101,D102,D103,D104,D105,D106,D107,D202,E501,RST301,RST304,W503,E203,C417,T202,S101 -; extend-ignore = E203 +ignore = W503 exclude = .git,.*_cache,.eggs,*.egg-info,__pycache__,venv,.tox,docs enable-extensions = G select = B,C,D,E,F,G,I,N,S,T,W,B902,B903,R