1616# Copyright (c) OWASP Foundation. All Rights Reserved.
1717
1818from glob import iglob
19+ from itertools import chain
1920from os .path import join
2021from typing import Generator
2122from unittest import TestCase
2526from cyclonedx .exception import MissingOptionalDependencyException
2627from cyclonedx .schema import OutputFormat , SchemaVersion
2728from 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
2930
3031UNSUPPORTED_SCHEMA_VERSIONS = {SchemaVersion .V1_0 , SchemaVersion .V1_1 , }
3132
3233
33- def _dp (prefix : str ) -> Generator :
34+ def _dp_sv_tf (prefix : str ) -> Generator :
3435 return (
3536 DpTuple ((sv , tf )) for sv in SchemaVersion if sv not in UNSUPPORTED_SCHEMA_VERSIONS
3637 for tf in iglob (join (SCHEMA_TESTDATA_DIRECTORY , sv .to_version (), f'{ prefix } -*.json' ))
3738 )
3839
3940
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+
4048@ddt
4149class TestJsonValidator (TestCase ):
4250
@@ -51,7 +59,10 @@ def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVers
5159 with self .assertRaisesRegex (ValueError , 'Unsupported schema_version' ):
5260 JsonValidator (schema_version )
5361
54- @idata (_dp ('valid' ))
62+ @idata (chain (
63+ _dp_sv_tf ('valid' ),
64+ _dp_sv_own ()
65+ ))
5566 @unpack
5667 def test_validate_no_none (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
5768 validator = JsonValidator (schema_version )
@@ -63,7 +74,7 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
6374 self .skipTest ('MissingOptionalDependencyException' )
6475 self .assertIsNone (validation_error )
6576
66- @idata (_dp ('invalid' ))
77+ @idata (_dp_sv_tf ('invalid' ))
6778 @unpack
6879 def test_validate_expected_error (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
6980 validator = JsonValidator (schema_version )
@@ -85,7 +96,10 @@ def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVers
8596 with self .assertRaisesRegex (ValueError , 'Unsupported schema_version' ):
8697 JsonStrictValidator (schema_version )
8798
88- @idata (_dp ('valid' ))
99+ @idata (chain (
100+ _dp_sv_tf ('valid' ),
101+ _dp_sv_own ()
102+ ))
89103 @unpack
90104 def test_validate_no_none (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
91105 validator = JsonStrictValidator (schema_version )
@@ -97,7 +111,7 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
97111 self .skipTest ('MissingOptionalDependencyException' )
98112 self .assertIsNone (validation_error )
99113
100- @idata (_dp ('invalid' ))
114+ @idata (_dp_sv_tf ('invalid' ))
101115 @unpack
102116 def test_validate_expected_error (self , schema_version : SchemaVersion , test_data_file : str ) -> None :
103117 validator = JsonStrictValidator (schema_version )
0 commit comments