16
16
# Copyright (c) OWASP Foundation. All Rights Reserved.
17
17
18
18
from glob import iglob
19
+ from itertools import chain
19
20
from os .path import join
20
21
from typing import Generator
21
22
from unittest import TestCase
25
26
from cyclonedx .exception import MissingOptionalDependencyException
26
27
from cyclonedx .schema import OutputFormat , SchemaVersion
27
28
from cyclonedx .validation .json import JsonStrictValidator , JsonValidator
28
- from tests import SCHEMA_TESTDATA_DIRECTORY , DpTuple
29
+ from tests import OWN_DATA_DIRECTORY , SCHEMA_TESTDATA_DIRECTORY , DpTuple
29
30
30
31
UNSUPPORTED_SCHEMA_VERSIONS = {SchemaVersion .V1_0 , SchemaVersion .V1_1 , }
31
32
32
33
33
- def _dp (prefix : str ) -> Generator :
34
+ def _dp_sv_tf (prefix : str ) -> Generator :
34
35
return (
35
36
DpTuple ((sv , tf )) for sv in SchemaVersion if sv not in UNSUPPORTED_SCHEMA_VERSIONS
36
37
for tf in iglob (join (SCHEMA_TESTDATA_DIRECTORY , sv .to_version (), f'{ prefix } -*.json' ))
37
38
)
38
39
39
40
41
+ def _dp_sv_own () -> Generator :
42
+ return (
43
+ DpTuple ((sv , tf )) for sv in SchemaVersion if sv not in UNSUPPORTED_SCHEMA_VERSIONS
44
+ for tf in iglob (join (OWN_DATA_DIRECTORY , 'json' , sv .to_version (), '*.json' ))
45
+ )
46
+
47
+
40
48
@ddt
41
49
class TestJsonValidator (TestCase ):
42
50
@@ -51,7 +59,10 @@ def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVers
51
59
with self .assertRaisesRegex (ValueError , 'Unsupported schema_version' ):
52
60
JsonValidator (schema_version )
53
61
54
- @idata (_dp ('valid' ))
62
+ @idata (chain (
63
+ _dp_sv_tf ('valid' ),
64
+ _dp_sv_own ()
65
+ ))
55
66
@unpack
56
67
def test_validate_no_none (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
57
68
validator = JsonValidator (schema_version )
@@ -63,7 +74,7 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
63
74
self .skipTest ('MissingOptionalDependencyException' )
64
75
self .assertIsNone (validation_error )
65
76
66
- @idata (_dp ('invalid' ))
77
+ @idata (_dp_sv_tf ('invalid' ))
67
78
@unpack
68
79
def test_validate_expected_error (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
69
80
validator = JsonValidator (schema_version )
@@ -85,7 +96,10 @@ def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVers
85
96
with self .assertRaisesRegex (ValueError , 'Unsupported schema_version' ):
86
97
JsonStrictValidator (schema_version )
87
98
88
- @idata (_dp ('valid' ))
99
+ @idata (chain (
100
+ _dp_sv_tf ('valid' ),
101
+ _dp_sv_own ()
102
+ ))
89
103
@unpack
90
104
def test_validate_no_none (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
91
105
validator = JsonStrictValidator (schema_version )
@@ -97,7 +111,7 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
97
111
self .skipTest ('MissingOptionalDependencyException' )
98
112
self .assertIsNone (validation_error )
99
113
100
- @idata (_dp ('invalid' ))
114
+ @idata (_dp_sv_tf ('invalid' ))
101
115
@unpack
102
116
def test_validate_expected_error (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
103
117
validator = JsonStrictValidator (schema_version )
0 commit comments