You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""Unit tests for parser schema validator."""
|
|
|
|
|
|
def test_valid_output_passes(sample_parser_output):
|
|
from libs.parser.schema_validator import validate_parser_output
|
|
errors = validate_parser_output(sample_parser_output)
|
|
assert errors == []
|
|
|
|
|
|
def test_missing_required_field(sample_parser_output):
|
|
from libs.parser.schema_validator import validate_parser_output
|
|
del sample_parser_output["event_type"]
|
|
errors = validate_parser_output(sample_parser_output)
|
|
assert len(errors) > 0
|
|
|
|
|
|
def test_invalid_event_type(sample_parser_output):
|
|
from libs.parser.schema_validator import validate_parser_output
|
|
sample_parser_output["event_type"] = "not_a_valid_type"
|
|
errors = validate_parser_output(sample_parser_output)
|
|
assert len(errors) > 0
|
|
|
|
|
|
def test_confidence_out_of_range(sample_parser_output):
|
|
from libs.parser.schema_validator import validate_parser_output
|
|
sample_parser_output["confidence"]["overall"] = 1.5
|
|
errors = validate_parser_output(sample_parser_output)
|
|
assert len(errors) > 0
|
|
|
|
|
|
def test_is_valid_function(sample_parser_output):
|
|
from libs.parser.schema_validator import is_valid
|
|
assert is_valid(sample_parser_output) is True
|
|
|
|
|
|
def test_is_valid_false(sample_parser_output):
|
|
from libs.parser.schema_validator import is_valid
|
|
sample_parser_output["event_direction"] = "invalid_value"
|
|
assert is_valid(sample_parser_output) is False
|