diff --git a/docs/index.rst b/docs/index.rst index 1b9b6fe..f89daba 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -20,7 +20,7 @@ Installation .. md-tab-set:: - .. md-tab-item:: Pip + PyPI (recommented) + .. md-tab-item:: Pip + PyPI (recommended) .. code-block:: console diff --git a/openapi_schema_validator/shortcuts.py b/openapi_schema_validator/shortcuts.py index f6e940d..b9d60aa 100644 --- a/openapi_schema_validator/shortcuts.py +++ b/openapi_schema_validator/shortcuts.py @@ -15,6 +15,9 @@ def validate( *args: Any, **kwargs: Any ) -> None: + """ + Validate an instance against a given schema using the specified validator class. + """ schema_dict = cast(dict[str, Any], schema) cls.check_schema(schema_dict) validator = cls(schema_dict, *args, **kwargs) diff --git a/tests/unit/test_shortcut.py b/tests/unit/test_shortcut.py index 0ec80c7..26eca30 100644 --- a/tests/unit/test_shortcut.py +++ b/tests/unit/test_shortcut.py @@ -1,21 +1,34 @@ -from unittest import TestCase +import pytest from openapi_schema_validator import validate -class ValidateTest(TestCase): - def test_validate_does_not_mutate_schema_adding_nullable_key(self): - schema = { - "type": "object", - "properties": { - "email": {"type": "string"}, - "enabled": { - "type": "boolean", - }, +@pytest.fixture(scope="function") +def schema(): + return { + "type": "object", + "properties": { + "email": {"type": "string"}, + "enabled": { + "type": "boolean", }, - "example": {"enabled": False, "email": "foo@bar.com"}, - } + }, + "example": {"enabled": False, "email": "foo@bar.com"}, + } - validate({"email": "foo@bar.com"}, schema) - self.assertTrue("nullable" not in schema["properties"]["email"].keys()) +def test_validate_does_not_add_nullable_to_schema(schema): + """ + Verify that calling validate does not add the 'nullable' key to the schema + """ + validate({"email": "foo@bar.com"}, schema) + assert "nullable" not in schema["properties"]["email"].keys() + + +def test_validate_does_not_mutate_schema(schema): + """ + Verify that calling validate does not mutate the schema + """ + original_schema = schema.copy() + validate({"email": "foo@bar.com"}, schema) + assert schema == original_schema