diff --git a/PKG-INFO b/PKG-INFO index 6d373a3..82ecede 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,31 +1,31 @@ Metadata-Version: 2.1 Name: swh.vault -Version: 0.3.3 +Version: 0.3.4 Summary: Software Heritage vault Home-page: https://forge.softwareheritage.org/diffusion/DVAU/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-vault Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-vault/ Description: swh-vault ========= User-facing service that allows to retrieve parts of the archive as self-contained bundles. See the [documentation](https://docs.softwareheritage.org/devel/swh-vault/index.html) for more details. Platform: UNKNOWN Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: testing diff --git a/conftest.py b/conftest.py index 92cc362..8a741d1 100644 --- a/conftest.py +++ b/conftest.py @@ -1,6 +1,10 @@ # Copyright (C) 2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -pytest_plugins = ["swh.storage.pytest_plugin", "swh.loader.pytest_plugin"] +pytest_plugins = [ + "aiohttp.pytest_plugin", + "swh.storage.pytest_plugin", + "swh.loader.pytest_plugin", +] diff --git a/requirements-test.txt b/requirements-test.txt index 66b4544..fed1464 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,8 +1,7 @@ pytest -pytest-aiohttp pytest-postgresql dulwich >= 0.18.7 swh.loader.core swh.loader.git >= 0.0.52 swh.storage[testing] pytest-mock diff --git a/swh.vault.egg-info/PKG-INFO b/swh.vault.egg-info/PKG-INFO index 6d373a3..82ecede 100644 --- a/swh.vault.egg-info/PKG-INFO +++ b/swh.vault.egg-info/PKG-INFO @@ -1,31 +1,31 @@ Metadata-Version: 2.1 Name: swh.vault -Version: 0.3.3 +Version: 0.3.4 Summary: Software Heritage vault Home-page: https://forge.softwareheritage.org/diffusion/DVAU/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-vault Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-vault/ Description: swh-vault ========= User-facing service that allows to retrieve parts of the archive as self-contained bundles. See the [documentation](https://docs.softwareheritage.org/devel/swh-vault/index.html) for more details. Platform: UNKNOWN Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: testing diff --git a/swh.vault.egg-info/requires.txt b/swh.vault.egg-info/requires.txt index 20aa219..0ac954a 100644 --- a/swh.vault.egg-info/requires.txt +++ b/swh.vault.egg-info/requires.txt @@ -1,21 +1,20 @@ click flask psycopg2 python-dateutil fastimport typing-extensions swh.core[db,http]>=0.5 swh.model>=0.3 swh.objstorage>=0.0.17 swh.scheduler>=0.7.0 swh.storage>=0.0.106 [testing] pytest -pytest-aiohttp pytest-postgresql dulwich>=0.18.7 swh.loader.core swh.loader.git>=0.0.52 swh.storage[testing] pytest-mock diff --git a/swh/vault/tests/test_server.py b/swh/vault/tests/test_server.py index bd96ef4..6072e54 100644 --- a/swh/vault/tests/test_server.py +++ b/swh/vault/tests/test_server.py @@ -1,157 +1,157 @@ # Copyright (C) 2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import copy import os from typing import Any, Dict import pytest import yaml from swh.core.api.serializers import json_dumps, msgpack_dumps, msgpack_loads from swh.vault.api.server import ( VaultServerApp, check_config, make_app, make_app_from_configfile, ) from swh.vault.tests.test_backend import TEST_HEX_ID def test_make_app_from_file_missing(): with pytest.raises(ValueError, match="Missing configuration path."): make_app_from_configfile() def test_make_app_from_file_does_not_exist(tmp_path): conf_path = os.path.join(str(tmp_path), "vault-server.yml") assert os.path.exists(conf_path) is False with pytest.raises( ValueError, match=f"Configuration path {conf_path} should exist." ): make_app_from_configfile(conf_path) def test_make_app_from_env_variable(swh_vault_config_file): """Server initialization happens through env variable when no path is provided """ app = make_app_from_configfile() assert app is not None def test_make_app_from_file(swh_local_vault_config, tmp_path): """Server initialization happens trough path if provided """ conf_path = os.path.join(str(tmp_path), "vault-server.yml") with open(conf_path, "w") as f: f.write(yaml.dump(swh_local_vault_config)) app = make_app_from_configfile(conf_path) assert app is not None @pytest.fixture def async_app(swh_local_vault_config: Dict[str, Any],) -> VaultServerApp: """Instantiate the vault server application. Note: This requires the db setup to run (fixture swh_vault in charge of this) """ return make_app(swh_local_vault_config) @pytest.fixture def cli(async_app, aiohttp_client, loop): return loop.run_until_complete(aiohttp_client(async_app)) async def test_client_index(cli): resp = await cli.get("/") assert resp.status == 200 async def test_client_cook_notfound(cli): resp = await cli.post( "/cook", data=json_dumps({"obj_type": "directory", "obj_id": TEST_HEX_ID}), headers=[("Content-Type", "application/json")], ) assert resp.status == 400 content = msgpack_loads(await resp.content.read()) - assert content["exception"]["type"] == "NotFoundExc" - assert content["exception"]["args"] == [f"directory {TEST_HEX_ID} was not found."] + assert content["type"] == "NotFoundExc" + assert content["args"] == [f"directory {TEST_HEX_ID} was not found."] async def test_client_progress_notfound(cli): resp = await cli.post( "/progress", data=json_dumps({"obj_type": "directory", "obj_id": TEST_HEX_ID}), headers=[("Content-Type", "application/json")], ) assert resp.status == 400 content = msgpack_loads(await resp.content.read()) - assert content["exception"]["type"] == "NotFoundExc" - assert content["exception"]["args"] == [f"directory {TEST_HEX_ID} was not found."] + assert content["type"] == "NotFoundExc" + assert content["args"] == [f"directory {TEST_HEX_ID} was not found."] async def test_client_batch_cook_invalid_type(cli): resp = await cli.post( "/batch_cook", data=msgpack_dumps({"batch": [("foobar", [])]}), headers={"Content-Type": "application/x-msgpack"}, ) assert resp.status == 400 content = msgpack_loads(await resp.content.read()) - assert content["exception"]["type"] == "NotFoundExc" - assert content["exception"]["args"] == ["foobar is an unknown type."] + assert content["type"] == "NotFoundExc" + assert content["args"] == ["foobar is an unknown type."] async def test_client_batch_progress_notfound(cli): resp = await cli.post( "/batch_progress", data=msgpack_dumps({"batch_id": 1}), headers={"Content-Type": "application/x-msgpack"}, ) assert resp.status == 400 content = msgpack_loads(await resp.content.read()) - assert content["exception"]["type"] == "NotFoundExc" - assert content["exception"]["args"] == ["Batch 1 does not exist."] + assert content["type"] == "NotFoundExc" + assert content["args"] == ["Batch 1 does not exist."] def test_check_config_missing_vault_configuration() -> None: """Irrelevant configuration file path raises""" with pytest.raises(ValueError, match="missing 'vault' configuration"): check_config({}) def test_check_config_not_local() -> None: """Wrong configuration raises""" expected_error = ( "The vault backend can only be started with a 'local' configuration" ) with pytest.raises(EnvironmentError, match=expected_error): check_config({"vault": {"cls": "remote"}}) @pytest.mark.parametrize("missing_key", ["storage", "cache", "scheduler"]) def test_check_config_missing_key(missing_key, swh_vault_config) -> None: """Any other configuration than 'local' (the default) is rejected""" config_ok = {"vault": {"cls": "local", **swh_vault_config}} config_ko = copy.deepcopy(config_ok) config_ko["vault"].pop(missing_key, None) expected_error = f"invalid configuration: missing {missing_key} config entry" with pytest.raises(ValueError, match=expected_error): check_config(config_ko) @pytest.mark.parametrize("missing_key", ["storage", "cache", "scheduler"]) def test_check_config_ok(missing_key, swh_vault_config) -> None: """Any other configuration than 'local' (the default) is rejected""" config_ok = {"vault": {"cls": "local", **swh_vault_config}} assert check_config(config_ok) is not None