diff --git a/PKG-INFO b/PKG-INFO index f2275485..ab81d4de 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,37 +1,37 @@ Metadata-Version: 2.1 Name: swh.deposit -Version: 0.0.83 +Version: 0.0.84 Summary: Software Heritage Deposit Server Home-page: https://forge.softwareheritage.org/source/swh-deposit/ 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-deposit Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-deposit/ Description: # swh-deposit This is [Software Heritage](https://www.softwareheritage.org)'s [SWORD 2.0](http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html) Server implementation, as well as a simple client to upload deposits on the server. **S.W.O.R.D** (**S**imple **W**eb-Service **O**ffering **R**epository **D**eposit) is an interoperability standard for digital file deposit. This implementation will permit interaction between a client (a repository) and a server (SWH repository) to permit deposits of software source code archives and associated metadata. The documentation is at ./docs/README-specification.md 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 Provides-Extra: server diff --git a/swh.deposit.egg-info/PKG-INFO b/swh.deposit.egg-info/PKG-INFO index f2275485..ab81d4de 100644 --- a/swh.deposit.egg-info/PKG-INFO +++ b/swh.deposit.egg-info/PKG-INFO @@ -1,37 +1,37 @@ Metadata-Version: 2.1 Name: swh.deposit -Version: 0.0.83 +Version: 0.0.84 Summary: Software Heritage Deposit Server Home-page: https://forge.softwareheritage.org/source/swh-deposit/ 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-deposit Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-deposit/ Description: # swh-deposit This is [Software Heritage](https://www.softwareheritage.org)'s [SWORD 2.0](http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html) Server implementation, as well as a simple client to upload deposits on the server. **S.W.O.R.D** (**S**imple **W**eb-Service **O**ffering **R**epository **D**eposit) is an interoperability standard for digital file deposit. This implementation will permit interaction between a client (a repository) and a server (SWH repository) to permit deposits of software source code archives and associated metadata. The documentation is at ./docs/README-specification.md 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 Provides-Extra: server diff --git a/swh/deposit/loader/checker.py b/swh/deposit/loader/checker.py index 5c01027c..bb054529 100644 --- a/swh/deposit/loader/checker.py +++ b/swh/deposit/loader/checker.py @@ -1,48 +1,51 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-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 logging from typing import Mapping from swh.core.config import SWHConfig from swh.deposit.client import PrivateApiDepositClient logger = logging.getLogger(__name__) class DepositChecker(SWHConfig): """Deposit checker implementation. Trigger deposit's checks through the private api. """ CONFIG_BASE_FILENAME = "deposit/checker" DEFAULT_CONFIG = { "deposit": ("dict", {"url": "http://localhost:5006/1/private/", "auth": {},}) } def __init__(self, config=None): super().__init__() if config is None: self.config = self.parse_config_file() else: self.config = config self.client = PrivateApiDepositClient(config=self.config["deposit"]) def check(self, collection: str, deposit_id: str) -> Mapping[str, str]: status = None deposit_check_url = f"/{collection}/{deposit_id}/check/" + logger.debug("deposit-check-url: %s", deposit_check_url) try: r = self.client.check(deposit_check_url) + logger.debug("Check result: %s", r) status = "eventful" if r == "verified" else "failed" except Exception: - logger.exception("Failure during check on '%s'" % (deposit_check_url,)) + logger.exception("Failure during check on '%s'", deposit_check_url) status = "failed" + logger.debug("Check status: %s", status) return {"status": status} diff --git a/swh/deposit/tests/loader/test_tasks.py b/swh/deposit/tests/loader/test_tasks.py index 2e4fe804..c62fd45a 100644 --- a/swh/deposit/tests/loader/test_tasks.py +++ b/swh/deposit/tests/loader/test_tasks.py @@ -1,21 +1,69 @@ -# Copyright (C) 2018-2019 The Software Heritage developers +# Copyright (C) 2018-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 -from unittest.mock import patch +import pytest -@patch("swh.deposit.loader.checker.DepositChecker.check") -def test_deposit_check(checker, swh_config, swh_app, celery_session_worker): - checker.return_value = {"status": "uneventful"} +@pytest.mark.db +def test_deposit_check_eventful(mocker, swh_config, swh_app, celery_session_worker): + """Successful check should make the check succeed + """ + client = mocker.patch("swh.deposit.loader.checker.PrivateApiDepositClient.check") + client.return_value = "verified" + + collection = "collection" + deposit_id = 42 + res = swh_app.send_task( + "swh.deposit.loader.tasks.ChecksDepositTsk", args=[collection, deposit_id] + ) + assert res + res.wait() + assert res.successful() + + assert res.result == {"status": "eventful"} + client.assert_called_once_with(f"/{collection}/{deposit_id}/check/") + + +@pytest.mark.db +def test_deposit_check_failure(mocker, swh_config, swh_app, celery_session_worker): + """Unverified check status should make the check fail + + """ + client = mocker.patch("swh.deposit.loader.checker.PrivateApiDepositClient.check") + client.return_value = "not-verified" # will make the status "failed" + + collection = "collec" + deposit_id = 666 + res = swh_app.send_task( + "swh.deposit.loader.tasks.ChecksDepositTsk", args=[collection, deposit_id] + ) + assert res + res.wait() + assert res.successful() + + assert res.result == {"status": "failed"} + client.assert_called_once_with(f"/{collection}/{deposit_id}/check/") + + +@pytest.mark.db +def test_deposit_check_3(mocker, swh_config, swh_app, celery_session_worker): + """Unexpected failures should fail the check + + """ + client = mocker.patch("swh.deposit.loader.checker.PrivateApiDepositClient.check") + client.side_effect = ValueError("unexpected failure will make it fail") + + collection = "another-collection" + deposit_id = 999 res = swh_app.send_task( - "swh.deposit.loader.tasks.ChecksDepositTsk", args=["collection", 42] + "swh.deposit.loader.tasks.ChecksDepositTsk", args=[collection, deposit_id] ) assert res res.wait() assert res.successful() - assert res.result == {"status": "uneventful"} - checker.assert_called_once_with("collection", 42) + assert res.result == {"status": "failed"} + client.assert_called_once_with(f"/{collection}/{deposit_id}/check/") diff --git a/version.txt b/version.txt index 5ecc8642..439e1d3c 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.0.83-0-gd2559583 \ No newline at end of file +v0.0.84-0-g25d7f75b \ No newline at end of file