Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_fossology_license.py
Show All 9 Lines | |||||
import pytest | import pytest | ||||
from swh.indexer import fossology_license | from swh.indexer import fossology_license | ||||
from swh.indexer.fossology_license import ( | from swh.indexer.fossology_license import ( | ||||
FossologyLicenseIndexer, | FossologyLicenseIndexer, | ||||
FossologyLicensePartitionIndexer, | FossologyLicensePartitionIndexer, | ||||
compute_license, | compute_license, | ||||
) | ) | ||||
from swh.indexer.storage.model import ContentLicenseRow | |||||
from swh.indexer.tests.utils import ( | from swh.indexer.tests.utils import ( | ||||
BASE_TEST_CONFIG, | BASE_TEST_CONFIG, | ||||
SHA1_TO_LICENSES, | SHA1_TO_LICENSES, | ||||
CommonContentIndexerPartitionTest, | CommonContentIndexerPartitionTest, | ||||
CommonContentIndexerTest, | CommonContentIndexerTest, | ||||
fill_obj_storage, | fill_obj_storage, | ||||
fill_storage, | fill_storage, | ||||
filter_dict, | filter_dict, | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | def setUp(self): | ||||
self.indexer.catch_exceptions = False | self.indexer.catch_exceptions = False | ||||
fill_storage(self.indexer.storage) | fill_storage(self.indexer.storage) | ||||
fill_obj_storage(self.indexer.objstorage) | fill_obj_storage(self.indexer.objstorage) | ||||
def tearDown(self): | def tearDown(self): | ||||
super().tearDown() | super().tearDown() | ||||
fossology_license.compute_license = self.orig_compute_license | fossology_license.compute_license = self.orig_compute_license | ||||
def assert_results_ok(self, partition_id, nb_partitions, actual_results): | |||||
# TODO: remove this method when fossology_license endpoints moved away | |||||
# from dicts. | |||||
actual_result_rows = [] | |||||
for res in actual_results: | |||||
for license in res["licenses"]: | |||||
actual_result_rows.append( | |||||
ContentLicenseRow( | |||||
id=res["id"], | |||||
indexer_configuration_id=res["indexer_configuration_id"], | |||||
license=license, | |||||
) | |||||
) | |||||
super().assert_results_ok(partition_id, nb_partitions, actual_result_rows) | |||||
def test_fossology_w_no_tool(): | def test_fossology_w_no_tool(): | ||||
with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
FossologyLicenseIndexer(config=filter_dict(CONFIG, "tools")) | FossologyLicenseIndexer(config=filter_dict(CONFIG, "tools")) | ||||
def test_fossology_range_w_no_tool(): | def test_fossology_range_w_no_tool(): | ||||
with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
FossologyLicensePartitionIndexer(config=filter_dict(RANGE_CONFIG, "tools")) | FossologyLicensePartitionIndexer(config=filter_dict(RANGE_CONFIG, "tools")) |