diff --git a/swh/indexer/storage/__init__.py b/swh/indexer/storage/__init__.py --- a/swh/indexer/storage/__init__.py +++ b/swh/indexer/storage/__init__.py @@ -7,6 +7,8 @@ import json import psycopg2 +from collections import defaultdict + from swh.storage.common import db_transaction_generator, db_transaction from swh.storage.exc import StorageDBError from .db import Db @@ -319,9 +321,15 @@ tool (dict): Tool used to compute the license """ + d = defaultdict(list) for c in db.content_fossology_license_get_from_list(ids, cur): license = dict(zip(db.content_fossology_license_cols, c)) - yield converters.db_to_fossology_license(license) + + id_ = license['id'] + d[id_].append(converters.db_to_fossology_license(license)) + + for id_, facts in d.items(): + yield {id_: facts} @db_transaction() def content_fossology_license_add(self, licenses, conflict_update=False, diff --git a/swh/indexer/storage/converters.py b/swh/indexer/storage/converters.py --- a/swh/indexer/storage/converters.py +++ b/swh/indexer/storage/converters.py @@ -129,7 +129,6 @@ def db_to_fossology_license(license): return { - 'id': license['id'], 'licenses': license['licenses'], 'tool': { 'id': license['tool_id'], diff --git a/swh/indexer/tests/storage/test_converters.py b/swh/indexer/tests/storage/test_converters.py --- a/swh/indexer/tests/storage/test_converters.py +++ b/swh/indexer/tests/storage/test_converters.py @@ -158,7 +158,6 @@ } expected_license = { - 'id': b'some-id', 'licenses': ['GPL2.0'], 'tool': { 'id': 20, diff --git a/swh/indexer/tests/storage/test_storage.py b/swh/indexer/tests/storage/test_storage.py --- a/swh/indexer/tests/storage/test_storage.py +++ b/swh/indexer/tests/storage/test_storage.py @@ -823,9 +823,10 @@ [self.sha1_2, self.sha1_1])) expected_license = { - 'id': self.sha1_1, - 'licenses': ['GPL-2.0+'], - 'tool': tool, + self.sha1_1: [{ + 'licenses': ['GPL-2.0+'], + 'tool': tool, + }] } # then @@ -854,9 +855,10 @@ # then expected_license = { - 'id': self.sha1_1, - 'licenses': ['Apache-2.0'], - 'tool': tool, + self.sha1_1: [{ + 'licenses': ['Apache-2.0'], + 'tool': tool, + }] } self.assertEqual(actual_licenses, [expected_license]) @@ -871,9 +873,12 @@ actual_licenses = list(self.storage.content_fossology_license_get( [self.sha1_1])) - expected_license.update({ - 'licenses': ['Apache-2.0', 'BSD-2-Clause'], - }) + expected_license = { + self.sha1_1: [{ + 'licenses': ['Apache-2.0', 'BSD-2-Clause'], + 'tool': tool + }] + } # license did not change as the v2 was dropped. self.assertEqual(actual_licenses, [expected_license]) @@ -901,9 +906,10 @@ # then expected_license = { - 'id': self.sha1_1, - 'licenses': ['CECILL'], - 'tool': tool, + self.sha1_1: [{ + 'licenses': ['CECILL'], + 'tool': tool, + }] } self.assertEqual(actual_licenses, [expected_license]) @@ -920,9 +926,12 @@ [self.sha1_1])) # license did change as the v2 was used to overwrite v1 - expected_license.update({ - 'licenses': ['CECILL-2.0'] - }) + expected_license = { + self.sha1_1: [{ + 'licenses': ['CECILL-2.0'], + 'tool': tool, + }] + } self.assertEqual(actual_licenses, [expected_license]) @istest