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-375] test "document describes at least one element" #462

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tests/spdx/validation/test_document_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest

from spdx.model.document import Document, CreationInfo
from spdx.model.relationship import Relationship, RelationshipType
from spdx.validation.document_validator import validate_full_spdx_document
from spdx.validation.validation_message import ValidationMessage, ValidationContext, SpdxElementType
from tests.spdx.fixtures import document_fixture, creation_info_fixture, file_fixture, package_fixture, snippet_fixture
Expand Down Expand Up @@ -55,7 +56,25 @@ def test_spdx_version_handling(creation_info: CreationInfo, version_input: str,

assert validation_messages == expected

# TODO: https://github.com/spdx/tools-python/issues/375

@pytest.mark.parametrize("relationships",
[[Relationship("SPDXRef-DOCUMENT", RelationshipType.DESCRIBES, "SPDXRef-File")],
[Relationship("SPDXRef-File", RelationshipType.DESCRIBED_BY, "SPDXRef-DOCUMENT")]])
def test_document_describes_at_least_one_element(relationships):
document = document_fixture(relationships=relationships)
validation_messages: List[ValidationMessage] = validate_full_spdx_document(document)

assert validation_messages == []


def test_document_does_not_describe_an_element():
document = document_fixture(relationships=[Relationship("SPDXRef-Package", RelationshipType.DESCRIBES, "SPDXRef-File")])
validation_messages: List[ValidationMessage] = validate_full_spdx_document(document)

assert validation_messages == [ValidationMessage(
'there must be at least one relationship "SPDXRef-DOCUMENT DESCRIBES ..." or "... DESCRIBED_BY SPDXRef-DOCUMENT"',
ValidationContext(spdx_id="SPDXRef-DOCUMENT", element_type=SpdxElementType.DOCUMENT)
)]


def test_duplicated_spdx_ids():
Expand Down