forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_creation_info_validator.py
More file actions
42 lines (32 loc) · 1.91 KB
/
test_creation_info_validator.py
File metadata and controls
42 lines (32 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright (c) 2022 spdx contributors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import List
import pytest
from spdx.validation.creation_info_validator import validate_creation_info
from spdx.validation.validation_message import ValidationMessage, ValidationContext, SpdxElementType
from tests.spdx.fixtures import creation_info_fixture
def test_valid_creation_info():
creation_info = creation_info_fixture()
validation_messages: List[ValidationMessage] = validate_creation_info(creation_info)
assert validation_messages == []
@pytest.mark.parametrize \
("creation_info_input, spdx_id, expected_message",
[(creation_info_fixture(spdx_id="SPDXRef-doc"), "SPDXRef-doc",
'spdx_id must be "SPDXRef-DOCUMENT", but is: SPDXRef-doc'),
(creation_info_fixture(data_license="MIT"), "SPDXRef-DOCUMENT",
'data_license must be "CC0-1.0", but is: MIT'),
(creation_info_fixture(document_namespace="some_namespace"), "SPDXRef-DOCUMENT",
"document_namespace must be a valid URI specified in RFC-3986, but is: some_namespace"),
])
def test_invalid_creation_info(creation_info_input, expected_message, spdx_id):
validation_messages: List[ValidationMessage] = validate_creation_info(creation_info_input)
expected = ValidationMessage(expected_message, ValidationContext(spdx_id, None, SpdxElementType.DOCUMENT))
assert validation_messages == [expected]