Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/storage/test_storage.py
Show First 20 Lines • Show All 817 Lines • ▼ Show 20 Lines | def content_fossology_license_get(self): | ||||
# when | # when | ||||
self.storage.content_fossology_license_add([license1]) | self.storage.content_fossology_license_add([license1]) | ||||
# then | # then | ||||
actual_licenses = list(self.storage.content_fossology_license_get( | actual_licenses = list(self.storage.content_fossology_license_get( | ||||
[self.sha1_2, self.sha1_1])) | [self.sha1_2, self.sha1_1])) | ||||
expected_license = { | expected_license = { | ||||
'id': self.sha1_1, | self.sha1_1: [{ | ||||
'licenses': ['GPL-2.0+'], | 'licenses': ['GPL-2.0+'], | ||||
'tool': tool, | 'tool': tool, | ||||
}] | |||||
} | } | ||||
# then | # then | ||||
self.assertEqual(actual_licenses, [expected_license]) | self.assertEqual(actual_licenses, [expected_license]) | ||||
@istest | @istest | ||||
def content_fossology_license_add__new_license_added(self): | def content_fossology_license_add__new_license_added(self): | ||||
# given | # given | ||||
Show All 12 Lines | def content_fossology_license_add__new_license_added(self): | ||||
self.storage.content_fossology_license_add([license_v1]) | self.storage.content_fossology_license_add([license_v1]) | ||||
# when | # when | ||||
actual_licenses = list(self.storage.content_fossology_license_get( | actual_licenses = list(self.storage.content_fossology_license_get( | ||||
[self.sha1_1])) | [self.sha1_1])) | ||||
# then | # then | ||||
expected_license = { | expected_license = { | ||||
'id': self.sha1_1, | self.sha1_1: [{ | ||||
'licenses': ['Apache-2.0'], | 'licenses': ['Apache-2.0'], | ||||
'tool': tool, | 'tool': tool, | ||||
}] | |||||
} | } | ||||
self.assertEqual(actual_licenses, [expected_license]) | self.assertEqual(actual_licenses, [expected_license]) | ||||
# given | # given | ||||
license_v2 = license_v1.copy() | license_v2 = license_v1.copy() | ||||
license_v2.update({ | license_v2.update({ | ||||
'licenses': ['BSD-2-Clause'], | 'licenses': ['BSD-2-Clause'], | ||||
}) | }) | ||||
self.storage.content_fossology_license_add([license_v2]) | self.storage.content_fossology_license_add([license_v2]) | ||||
actual_licenses = list(self.storage.content_fossology_license_get( | actual_licenses = list(self.storage.content_fossology_license_get( | ||||
[self.sha1_1])) | [self.sha1_1])) | ||||
expected_license.update({ | expected_license = { | ||||
self.sha1_1: [{ | |||||
'licenses': ['Apache-2.0', 'BSD-2-Clause'], | 'licenses': ['Apache-2.0', 'BSD-2-Clause'], | ||||
}) | 'tool': tool | ||||
}] | |||||
} | |||||
# license did not change as the v2 was dropped. | # license did not change as the v2 was dropped. | ||||
self.assertEqual(actual_licenses, [expected_license]) | self.assertEqual(actual_licenses, [expected_license]) | ||||
@istest | @istest | ||||
def content_fossology_license_add__update_in_place_duplicate(self): | def content_fossology_license_add__update_in_place_duplicate(self): | ||||
# given | # given | ||||
tool = self.tools['nomos'] | tool = self.tools['nomos'] | ||||
Show All 11 Lines | def content_fossology_license_add__update_in_place_duplicate(self): | ||||
self.storage.content_fossology_license_add([license_v1]) | self.storage.content_fossology_license_add([license_v1]) | ||||
# when | # when | ||||
actual_licenses = list(self.storage.content_fossology_license_get( | actual_licenses = list(self.storage.content_fossology_license_get( | ||||
[self.sha1_1])) | [self.sha1_1])) | ||||
# then | # then | ||||
expected_license = { | expected_license = { | ||||
'id': self.sha1_1, | self.sha1_1: [{ | ||||
'licenses': ['CECILL'], | 'licenses': ['CECILL'], | ||||
'tool': tool, | 'tool': tool, | ||||
}] | |||||
} | } | ||||
self.assertEqual(actual_licenses, [expected_license]) | self.assertEqual(actual_licenses, [expected_license]) | ||||
# given | # given | ||||
license_v2 = license_v1.copy() | license_v2 = license_v1.copy() | ||||
license_v2.update({ | license_v2.update({ | ||||
'licenses': ['CECILL-2.0'] | 'licenses': ['CECILL-2.0'] | ||||
}) | }) | ||||
self.storage.content_fossology_license_add([license_v2], | self.storage.content_fossology_license_add([license_v2], | ||||
conflict_update=True) | conflict_update=True) | ||||
actual_licenses = list(self.storage.content_fossology_license_get( | actual_licenses = list(self.storage.content_fossology_license_get( | ||||
[self.sha1_1])) | [self.sha1_1])) | ||||
# license did change as the v2 was used to overwrite v1 | # license did change as the v2 was used to overwrite v1 | ||||
expected_license.update({ | expected_license = { | ||||
'licenses': ['CECILL-2.0'] | self.sha1_1: [{ | ||||
}) | 'licenses': ['CECILL-2.0'], | ||||
'tool': tool, | |||||
}] | |||||
} | |||||
self.assertEqual(actual_licenses, [expected_license]) | self.assertEqual(actual_licenses, [expected_license]) | ||||
@istest | @istest | ||||
def content_metadata_missing(self): | def content_metadata_missing(self): | ||||
# given | # given | ||||
tool_id = self.tools['swh-metadata-translator']['id'] | tool_id = self.tools['swh-metadata-translator']['id'] | ||||
metadata = [ | metadata = [ | ||||
▲ Show 20 Lines • Show All 545 Lines • Show Last 20 Lines |