Raise InvalidLicenseKeyError for the cases where the there is no corresponding :
(license_expression, licensing)
| 525 | |
| 526 | |
| 527 | def validate_spdx_license_keys(license_expression, licensing): |
| 528 | """ |
| 529 | Raise InvalidLicenseKeyError for the cases where the there is no corresponding : |
| 530 | |
| 531 | """ |
| 532 | from licensedcode.models import load_licenses |
| 533 | |
| 534 | license_keys = licensing.license_keys(license_expression) |
| 535 | license_db = get_licenses_db() |
| 536 | |
| 537 | messages = [] |
| 538 | |
| 539 | for key in license_keys: |
| 540 | if not type(key) == str: |
| 541 | msg = f"Invalid license key: {key} of type {type(key)}, license key should be a string" |
| 542 | messages.append(msg) |
| 543 | |
| 544 | lic = license_db.get(key, None) |
| 545 | if not lic: |
| 546 | licenses = load_licenses(with_deprecated=True) |
| 547 | if licenses.get(key, None): |
| 548 | msg = f"License key: {key} is deprecated license key in LicenseDB" |
| 549 | else: |
| 550 | msg = f"License key: {key} is not a valid license key from LicenseDB" |
| 551 | messages.append(msg) |
| 552 | |
| 553 | parsed = licensing.parse(key) |
| 554 | try: |
| 555 | parsed.render(template='{symbol.wrapped.spdx_license_key}') |
| 556 | except AttributeError: |
| 557 | msg = f"Error rendering SPDX license key for: {key}" |
| 558 | messages.append(msg) |
| 559 | pass |
| 560 | |
| 561 | if messages: |
| 562 | raise InvalidLicenseKeyError(f"ERROR in parsing license_expression: {license_expression}: type: {type(license_expression)} :{messages}") |
| 563 | |
| 564 | |
| 565 | class InvalidLicenseKeyError(Exception): |
no test coverage detected