From f872792407221eaec1332770a4e2bbbed4f356a2 Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont (@ardumont)" Date: Mon, 4 Nov 2019 14:44:49 +0100 Subject: [PATCH] debian.lister: Send origin url as load-debian task parameter Instead of the old origin dict. That's what the debian loaders (old and new) expect. --- swh/lister/debian/models.py | 27 +++++++++++++------------- swh/lister/debian/tests/test_lister.py | 1 + 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/swh/lister/debian/models.py b/swh/lister/debian/models.py index 4dfc5ad..c7a394d 100644 --- a/swh/lister/debian/models.py +++ b/swh/lister/debian/models.py @@ -19,6 +19,7 @@ from sqlalchemy import ( Table, UniqueConstraint, ) +from typing import Any, Mapping try: from sqlalchemy import JSON @@ -44,14 +45,11 @@ class Distribution(SQLBase): areas = relationship('Area', back_populates='distribution') - def origin_for_package(self, package_name, package_versions): - """Return the origin dictionary for the given package""" - return { - 'type': self.type, - 'url': '%s://%s/packages/%s' % ( - self.type, self.name, package_name - ), - } + def origin_for_package(self, package_name: str) -> str: + """Return the origin url for the given package + + """ + return '%s://%s/packages/%s' % (self.type, self.name, package_name) def __repr__(self): return 'Distribution(%s (%s) on %s)' % ( @@ -183,11 +181,12 @@ class DistributionSnapshot(SQLBase): distribution = relationship('Distribution') areas = relationship('AreaSnapshot', back_populates='snapshot') - def task_for_package(self, package_name, package_versions): - """Return the task dictionary for the given list of package versions""" - origin = self.distribution.origin_for_package( - package_name, package_versions, - ) + def task_for_package(self, package_name: str, + package_versions: Mapping) -> Mapping[str, Any]: + """Return the task dictionary for the given list of package versions + + """ + origin_url = self.distribution.origin_for_package(package_name) return { 'policy': 'oneshot', @@ -196,7 +195,7 @@ class DistributionSnapshot(SQLBase): 'arguments': { 'args': [], 'kwargs': { - 'url': origin, + 'url': origin_url, 'date': self.date.isoformat(), 'packages': package_versions, }, diff --git a/swh/lister/debian/tests/test_lister.py b/swh/lister/debian/tests/test_lister.py index 0b279c5..f8e7aa2 100644 --- a/swh/lister/debian/tests/test_lister.py +++ b/swh/lister/debian/tests/test_lister.py @@ -30,6 +30,7 @@ def test_lister_debian(lister_debian, datadir, requests_mock_datadir): assert set(kwargs.keys()) == {'url', 'date', 'packages'} logger.debug('kwargs: %s', kwargs) + assert isinstance(kwargs['url'], str) assert row['policy'] == 'oneshot' assert row['priority'] is None