Skip to content

Commit d29addb

Browse files
committed
Update get_license_detections_and_expression #3396
* Set default default_relation_license if the PackageData has no datasource_id * Create a test to ensure that we can create a Package whose type we do not have a DatafileHandler for Signed-off-by: Jono Yang <[email protected]>
1 parent fef2408 commit d29addb

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/packagedcode/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,16 @@ def get_license_detections_and_expression(self):
869869
if not self.extracted_license_statement:
870870
return [], None
871871

872-
return get_license_detections_and_expression(
873-
extracted_license_statement=self.extracted_license_statement,
872+
if self.datasource_id:
874873
default_relation_license=get_default_relation_license(
875874
datasource_id=self.datasource_id,
876-
),
875+
)
876+
else:
877+
default_relation_license = 'AND'
878+
879+
return get_license_detections_and_expression(
880+
extracted_license_statement=self.extracted_license_statement,
881+
default_relation_license=default_relation_license
877882
)
878883

879884

tests/packagedcode/test_package_models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,20 @@ def test_package_adder(package_uid, resource, codebase):
225225
for package_uid in for_packages:
226226
normalized_package_uid = purl_with_fake_uuid(package_uid)
227227
assert normalized_package_uid == test_package_uid
228+
229+
def test_create_package_not_handled_by_packagedcode(self):
230+
extracted_license_statement = [
231+
'gpl',
232+
'GNU General Public License version 2.0 (GPLv2)',
233+
]
234+
package = PackageData(
235+
type='sourceforge',
236+
name='openstunts',
237+
copyright='Copyright (c) openstunts project',
238+
extracted_license_statement=extracted_license_statement,
239+
)
240+
# Test generated fields
241+
assert package.purl == 'pkg:sourceforge/openstunts'
242+
assert package.holder == 'openstunts project'
243+
assert package.declared_license_expression == 'gpl-1.0-plus AND gpl-2.0'
244+
assert package.declared_license_expression_spdx == 'GPL-1.0-or-later AND GPL-2.0-only'

0 commit comments

Comments
 (0)