From 6d2e7aa17808e39ba9f493b65d662d0ddef5796c Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont (@ardumont)" Date: Sat, 1 Oct 2022 16:12:46 +0200 Subject: [PATCH] nixguix: Register task Related to T3781 --- setup.py | 1 + swh/lister/nixguix/__init__.py | 2 +- swh/lister/nixguix/tasks.py | 14 +++++++++++++ swh/lister/nixguix/tests/test_tasks.py | 27 ++++++++++++++++++++++++++ swh/lister/tests/test_cli.py | 4 ++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 swh/lister/nixguix/tasks.py create mode 100644 swh/lister/nixguix/tests/test_tasks.py diff --git a/setup.py b/setup.py index 54ea4b0..7c55f6c 100755 --- a/setup.py +++ b/setup.py @@ -72,6 +72,7 @@ setup( lister.golang=swh.lister.golang:register lister.hackage=swh.lister.hackage:register lister.launchpad=swh.lister.launchpad:register + lister.nixguix=swh.lister.nixguix:register lister.npm=swh.lister.npm:register lister.nuget=swh.lister.nuget:register lister.opam=swh.lister.opam:register diff --git a/swh/lister/nixguix/__init__.py b/swh/lister/nixguix/__init__.py index 5dd39c5..e3f5ff2 100644 --- a/swh/lister/nixguix/__init__.py +++ b/swh/lister/nixguix/__init__.py @@ -8,5 +8,5 @@ def register(): return { "lister": NixGuixLister, - "task_modules": ["%s.tasks" % __name__], + "task_modules": [f"{__name__}.tasks"], } diff --git a/swh/lister/nixguix/tasks.py b/swh/lister/nixguix/tasks.py new file mode 100644 index 0000000..23d9fd6 --- /dev/null +++ b/swh/lister/nixguix/tasks.py @@ -0,0 +1,14 @@ +# 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 celery import shared_task + + +@shared_task(name=__name__ + ".NixGuixListerTask") +def list_nixguix(**lister_args): + """Lister task for Arch Linux""" + from swh.lister.nixguix.lister import NixGuixLister + + return NixGuixLister.from_configfile(**lister_args).run().dict() diff --git a/swh/lister/nixguix/tests/test_tasks.py b/swh/lister/nixguix/tests/test_tasks.py new file mode 100644 index 0000000..8631046 --- /dev/null +++ b/swh/lister/nixguix/tests/test_tasks.py @@ -0,0 +1,27 @@ +# 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 swh.lister.pattern import ListerStats + +NAMESPACE = "swh.lister.nixguix" + + +def test_nixguix_lister(swh_scheduler_celery_app, swh_scheduler_celery_worker, mocker): + # setup the mocked ArchLister + lister = mocker.patch(f"{NAMESPACE}.lister.NixGuixLister") + lister.from_configfile.return_value = lister + stats = ListerStats(pages=1, origins=42) + lister.run.return_value = stats + + res = swh_scheduler_celery_app.send_task( + f"{NAMESPACE}.tasks.NixGuixListerTask", + ) + assert res + res.wait() + assert res.successful() + assert res.result == stats.dict() + + lister.from_configfile.assert_called_once_with() + lister.run.assert_called_once_with() diff --git a/swh/lister/tests/test_cli.py b/swh/lister/tests/test_cli.py index ed0f34e..a69ec1c 100644 --- a/swh/lister/tests/test_cli.py +++ b/swh/lister/tests/test_cli.py @@ -35,6 +35,10 @@ lister_args = { "url": "https://try.gogs.io/", "api_token": "secret", }, + "nixguix": { + "url": "https://guix.gnu.org/sources.json", + "origin_upstream": "https://git.savannah.gnu.org/cgit/guix.git/", + }, }