Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-540] change DESCRIBES validation #577

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/spdx/validation/document_validator.py
Expand Up @@ -70,11 +70,12 @@ def validate_full_spdx_document(document: Document, spdx_version: str = None) ->
document.relationships, RelationshipType.DESCRIBED_BY, document_id
)

if not document_describes_relationships + described_by_document_relationships:
only_a_single_package = len(document.packages) == 1 and not document.files and not document.snippets
if not only_a_single_package and not document_describes_relationships + described_by_document_relationships:
validation_messages.append(
ValidationMessage(
f'there must be at least one relationship "{document_id} DESCRIBES ..." or "... DESCRIBED_BY '
f'{document_id}"',
f'{document_id}" when there is not only a single package present',
ValidationContext(spdx_id=document_id, element_type=SpdxElementType.DOCUMENT),
)
)
Expand Down
17 changes: 15 additions & 2 deletions tests/spdx/validation/test_document_validator.py
Expand Up @@ -94,7 +94,20 @@ def test_document_describes_at_least_one_element(relationships):
assert validation_messages == []


def test_document_does_not_describe_an_element():
def test_document_does_not_describe_an_element_with_only_one_package():
document = document_fixture(
packages=[package_fixture()],
files=[],
snippets=[],
relationships=[],
annotations=[],
)
validation_messages: List[ValidationMessage] = validate_full_spdx_document(document)

assert validation_messages == []


def test_document_does_not_describe_an_element_with_multiple_elements():
document = document_fixture(
relationships=[Relationship("SPDXRef-Package", RelationshipType.DESCRIBES, "SPDXRef-File")]
)
Expand All @@ -103,7 +116,7 @@ def test_document_does_not_describe_an_element():
assert validation_messages == [
ValidationMessage(
f'there must be at least one relationship "{DOCUMENT_SPDX_ID} DESCRIBES ..." or "... DESCRIBED_BY '
f'{DOCUMENT_SPDX_ID}"',
f'{DOCUMENT_SPDX_ID}" when there is not only a single package present',
ValidationContext(spdx_id=DOCUMENT_SPDX_ID, element_type=SpdxElementType.DOCUMENT),
)
]
Expand Down