diff --git a/testing.requirements.txt b/testing.requirements.txt index 44e9792..633194e 100644 --- a/testing.requirements.txt +++ b/testing.requirements.txt @@ -2,4 +2,3 @@ pytest pytest-asyncio pytest-cov pytest-mock -pytest-tornado \ No newline at end of file diff --git a/tests/opr/__init__.py b/tests/operator_tests/__init__.py similarity index 100% rename from tests/opr/__init__.py rename to tests/operator_tests/__init__.py diff --git a/tests/srv/__init__.py b/tests/server_tests/__init__.py similarity index 100% rename from tests/srv/__init__.py rename to tests/server_tests/__init__.py diff --git a/tests/server_tests/test_key_handler.py b/tests/server_tests/test_key_handler.py new file mode 100644 index 0000000..29106fd --- /dev/null +++ b/tests/server_tests/test_key_handler.py @@ -0,0 +1,48 @@ +import json +import pathlib + +import pytest +from tornado.testing import AsyncHTTPTestCase + +from srv.server import make_app + + +@pytest.fixture(scope='function') +def tmp_path_cls(request, tmp_path): + request.cls.config_values = tmp_path + + +@pytest.mark.usefixtures("tmp_path_cls") +class TestKeyHandler(AsyncHTTPTestCase): + config_values: pathlib.Path + + def get_app(self): + return make_app(self.config_values) + + def test_root(self): + response = self.fetch('/') + self.assertEqual(response.code, 404) + + def test_not_found(self): + response = self.fetch('/key/not-found') + self.assertEqual(response.code, 404) + # self.assertEqual(response.body, 'Hello, world') + + def test_key(self): + test_file = self.config_values / "test" + test_file.write_text(json.dumps({"foo": "bar"})) + + response = self.fetch('/key/test') + self.assertEqual(response.code, 200) + self.assertEqual(response.body.decode(), json.dumps({"foo": "bar"})) + + test_file.unlink() + + def test_key_not_json(self): + test_file = self.config_values / "test" + test_file.write_text("something: not json") + + response = self.fetch('/key/test') + self.assertEqual(response.code, 400) + + test_file.unlink() diff --git a/tests/srv/test_key_handler.py b/tests/srv/test_key_handler.py deleted file mode 100644 index 4504763..0000000 --- a/tests/srv/test_key_handler.py +++ /dev/null @@ -1,31 +0,0 @@ -import json -import os.path -import pathlib - -from tornado.httpclient import HTTPClientError - -import pytest - -from srv.server import make_app - - -@pytest.fixture -def app(tmp_path): - return make_app(tmp_path) - - -@pytest.mark.gen_test -async def test_key_not_found(http_client, base_url): - with pytest.raises(HTTPClientError) as e: - await http_client.fetch(os.path.join(base_url, "key", "non_existent")) - assert e.value.code == 404 - - -@pytest.mark.gen_test -async def test_key_not_found(http_client, base_url, app): - path: pathlib.Path = app.settings["config_values"] - test_file = path / "test" - test_file.write_text(json.dumps({"foo": "bar"})) - response = await http_client.fetch(os.path.join(base_url, "key", "test")) - assert response.code == 200 - assert response.body.decode() == json.dumps({"foo": "bar"})