pypi: Allow passing configuration arguments to task

The constructor allows it but not the celery task.

This also aligns the behavior with other lister tasks.
This commit is contained in:
Antoine R. Dumont (@ardumont) 2023-08-04 15:34:02 +02:00
parent 928d592e10
commit fcfb7004db
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
2 changed files with 9 additions and 6 deletions

View file

@ -1,4 +1,4 @@
# Copyright (C) 2018-2021 the Software Heritage developers
# Copyright (C) 2018-2023 the Software Heritage developers
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@ -8,9 +8,9 @@ from .lister import PyPILister
@shared_task(name=f"{__name__}.PyPIListerTask")
def list_pypi():
def list_pypi(**lister_args):
"Full listing of the PyPI registry"
lister = PyPILister.from_configfile()
lister = PyPILister.from_configfile(**lister_args)
return lister.run().dict()

View file

@ -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
@ -21,10 +21,13 @@ def test_pypi_full_lister(
lister.from_configfile.return_value = lister
lister.run.return_value = ListerStats(pages=1, origins=0)
res = swh_scheduler_celery_app.send_task("swh.lister.pypi.tasks.PyPIListerTask")
kwargs = dict(enable_origins=False)
res = swh_scheduler_celery_app.send_task(
"swh.lister.pypi.tasks.PyPIListerTask", kwargs=kwargs
)
assert res
res.wait()
assert res.successful()
lister.from_configfile.assert_called_once_with()
lister.from_configfile.assert_called_once_with(**kwargs)
lister.run.assert_called_once_with()