diff --git a/mypy.ini b/mypy.ini index e6a8ff0..8dc0aff 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,18 +1,21 @@ [mypy] namespace_packages = True warn_unused_ignores = True # 3rd party libraries without stubs (yet) [mypy-pkg_resources.*] ignore_missing_imports = True [mypy-pytest.*] ignore_missing_imports = True # [mypy-add_your_lib_here.*] # ignore_missing_imports = True [mypy-breezy.*] ignore_missing_imports = True + +[mypy-celery.*] +ignore_missing_imports = True diff --git a/swh/loader/bzr/tasks.py b/swh/loader/bzr/tasks.py new file mode 100644 index 0000000..d192163 --- /dev/null +++ b/swh/loader/bzr/tasks.py @@ -0,0 +1,26 @@ +# Copyright (C) 2022 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 typing import Optional + +from celery import shared_task + +from swh.loader.core.utils import parse_visit_date + +from .loader import BazaarLoader + + +@shared_task(name=__name__ + ".LoadBazaar") +def load_bzr( + *, url: str, directory: Optional[str] = None, visit_date: Optional[str] = None +): + """Bazaar repository loading + + Args: see :func:`BazaarLoader` constructor. + """ + loader = BazaarLoader.from_configfile( + url=url, directory=directory, visit_date=parse_visit_date(visit_date) + ) + return loader.load() diff --git a/swh/loader/bzr/tests/test_tasks.py b/swh/loader/bzr/tests/test_tasks.py new file mode 100644 index 0000000..aa2330f --- /dev/null +++ b/swh/loader/bzr/tests/test_tasks.py @@ -0,0 +1,23 @@ +# Copyright (C) 2022 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 + + +def test_loader( + mocker, swh_config, swh_scheduler_celery_app, swh_scheduler_celery_worker +): + mock_loader = mocker.patch("swh.loader.bzr.loader.BazaarLoader.load") + mock_loader.return_value = {"status": "eventful"} + + res = swh_scheduler_celery_app.send_task( + "swh.loader.bzr.tasks.LoadBazaar", + kwargs={"url": "origin_url", "directory": "/some/repo", "visit_date": "now",}, + ) + + assert res + res.wait() + assert res.successful() + + assert res.result == {"status": "eventful"} + mock_loader.assert_called_once_with()