Skip to content

Commit

Permalink
some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-ai committed Sep 16, 2024
1 parent 31353f3 commit 59f3fda
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/unit/library/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,36 @@ def test_bad_object(self, bad_string, good_bytes, failure_byte, allowed_bytes, m
)


class TestObjectWithMissingRequired:
def test_required_is_required(self):
schema = {"type": "object", "properties": {"a": {"type": "integer"}}, "required": ["b"]}
generate_and_check({"b": 1}, schema)
generate_and_check({"a": 1, "b": "xyz"}, schema)
check_match_failure(
bad_string=_to_compact_json(
{"a": 1}
),
schema_obj=schema,
)

def test_validated_against_additionalProperties(self):
schema = {"type": "object", "properties": {"a": {"type": "integer"}}, "required": ["b"], "additionalProperties": {"type": "integer"}}
generate_and_check({"b": 1}, schema)
generate_and_check({"a": 1, "b": 42}, schema)
check_match_failure(
bad_string=_to_compact_json(
{"a": 1, "b": "string"}
),
schema_obj=schema,
)

def test_false_additionalProperties_fails(self):
schema = {"type": "object", "properties": {"a": {"type": "integer"}}, "required": ["b", "c"], "additionalProperties": False}
with pytest.raises(ValueError) as ve:
_ = gen_json(schema=schema)
assert ve.value.args[0] == "Required properties not in properties but additionalProperties is False. Missing required properties: {'b', 'c'}"


class TestSimpleArray:
# These are array without references
@pytest.mark.parametrize("target_obj", [[], [0], [34, 56], [1, 2, 3], [9, 8, 7, 6]])
Expand Down

0 comments on commit 59f3fda

Please sign in to comment.