From 928d592e104fdd9dd65c65816f118707cf4a877c Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont (@ardumont)" <ardumont@softwareheritage.org> Date: Fri, 4 Aug 2023 15:18:22 +0200 Subject: [PATCH] sourceforge: Allow passing configuration arguments to task The constructor allows it but not the celery task. This also aligns the behavior with other lister tasks. --- swh/lister/sourceforge/tasks.py | 14 ++++++++------ swh/lister/sourceforge/tests/test_tasks.py | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/swh/lister/sourceforge/tasks.py b/swh/lister/sourceforge/tasks.py index fb111be3..6b55bdca 100644 --- a/swh/lister/sourceforge/tasks.py +++ b/swh/lister/sourceforge/tasks.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2021 the Software Heritage developers +# Copyright (C) 2019-2023 the Software Heritage developers # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -10,15 +10,17 @@ from swh.lister.sourceforge.lister import SourceForgeLister @shared_task(name=__name__ + ".FullSourceForgeLister") -def list_sourceforge_full() -> Dict[str, int]: +def list_sourceforge_full(**lister_args) -> Dict[str, int]: """Full update of a SourceForge instance""" - return SourceForgeLister.from_configfile().run().dict() + return SourceForgeLister.from_configfile(**lister_args).run().dict() @shared_task(name=__name__ + ".IncrementalSourceForgeLister") -def list_sourceforge_incremental() -> Dict[str, int]: - """Full update of a SourceForge instance""" - return SourceForgeLister.from_configfile(incremental=True).run().dict() +def list_sourceforge_incremental(**lister_args) -> Dict[str, int]: + """Incremental update of a SourceForge instance""" + return ( + SourceForgeLister.from_configfile(incremental=True, **lister_args).run().dict() + ) @shared_task(name=__name__ + ".ping") diff --git a/swh/lister/sourceforge/tests/test_tasks.py b/swh/lister/sourceforge/tests/test_tasks.py index 51752a90..994935ca 100644 --- a/swh/lister/sourceforge/tests/test_tasks.py +++ b/swh/lister/sourceforge/tests/test_tasks.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2021 The Software Heritage developers +# Copyright (C) 2019-2023 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 @@ -24,14 +24,16 @@ def test_sourceforge_full_lister_task( mock_lister.from_configfile.return_value = mock_lister mock_lister.run.return_value = stats + kwargs = dict(enable_origins=False) res = swh_scheduler_celery_app.send_task( - "swh.lister.sourceforge.tasks.FullSourceForgeLister" + "swh.lister.sourceforge.tasks.FullSourceForgeLister", + kwargs=kwargs, ) assert res res.wait() assert res.successful() - mock_lister.from_configfile.assert_called_once() + mock_lister.from_configfile.assert_called_once_with(**kwargs) mock_lister.run.assert_called_once() assert res.result == stats.dict() @@ -45,12 +47,12 @@ def test_incremental_listing( mock_lister.run.return_value = stats res = swh_scheduler_celery_app.send_task( - "swh.lister.sourceforge.tasks.IncrementalSourceForgeLister" + "swh.lister.sourceforge.tasks.IncrementalSourceForgeLister", ) assert res res.wait() assert res.successful() - mock_lister.from_configfile.assert_called_once() + mock_lister.from_configfile.assert_called_once_with(incremental=True) mock_lister.run.assert_called_once() assert res.result == stats.dict() -- GitLab