Skip to content

Commit

Permalink
tests: use internal json strict validation
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Sep 23, 2023
1 parent 839fe11 commit 7186b52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from cyclonedx.exception import MissingOptionalDependencyException
from cyclonedx.output import SchemaVersion
from cyclonedx.validation.json import JsonValidator
from cyclonedx.validation.json import JsonStrictValidator
from cyclonedx.validation.xml import XmlValidator

single_uuid: str = 'urn:uuid:{}'.format(uuid4())
Expand All @@ -40,7 +40,7 @@ class BaseJsonTestCase(TestCase):

def assertValidAgainstSchema(self, bom_json: str, schema_version: SchemaVersion) -> None:
try:
validation_error = JsonValidator(schema_version).validate_str(bom_json)
validation_error = JsonStrictValidator(schema_version).validate_str(bom_json)
except MissingOptionalDependencyException:
return # some deps are missing - skip the validation
self.assertIsNone(validation_error,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ def test_as_expected(self, of: OutputFormat, sv: SchemaVersion) -> None:
@unpack
def test_fails_on_wrong_args(self, of: OutputFormat, sv: SchemaVersion, raisesRegex: Tuple) -> None:
bom = Mock(spec=Bom)
with self.assertRaisesRegexp(*raisesRegex):
with self.assertRaisesRegex(*raisesRegex):
get_outputter(bom, of, sv)
9 changes: 6 additions & 3 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
from cyclonedx.schema import OutputFormat, SchemaVersion
from cyclonedx.validation import get_instance as get_validator

UndefinedFormatVersion = {(OutputFormat.JSON, SchemaVersion.V1_1), (OutputFormat.JSON, SchemaVersion.V1_0), }
UNDEFINED_FORMAT_VERSION = {
(OutputFormat.JSON, SchemaVersion.V1_1),
(OutputFormat.JSON, SchemaVersion.V1_0),
}


@ddt
Expand All @@ -36,7 +39,7 @@ class TestGetInstance(TestCase):
@named_data(*([f'{f.name} {v.name}', f, v]
for f, v
in product(OutputFormat, SchemaVersion)
if (f, v) not in UndefinedFormatVersion))
if (f, v) not in UNDEFINED_FORMAT_VERSION))
@unpack
def test_as_expected(self, of: OutputFormat, sv: SchemaVersion) -> None:
validator = get_validator(of, sv)
Expand All @@ -45,7 +48,7 @@ def test_as_expected(self, of: OutputFormat, sv: SchemaVersion) -> None:

@data(
*(('foo', sv, (TypeError, "unexpected output_format: 'foo'")) for sv in SchemaVersion),
*((f, v, (ValueError, f'unsupported schema_version: {v}')) for f, v in UndefinedFormatVersion)
*((f, v, (ValueError, f'unsupported schema_version: {v}')) for f, v in UNDEFINED_FORMAT_VERSION)
)
@unpack
def test_fails_on_wrong_args(self, of: OutputFormat, sv: SchemaVersion, raisesRegex: Tuple) -> None:
Expand Down

0 comments on commit 7186b52

Please sign in to comment.