File tree Expand file tree Collapse file tree 3 files changed +31
-15
lines changed
Expand file tree Collapse file tree 3 files changed +31
-15
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ Installation
2020
2121.. md-tab-set ::
2222
23- .. md-tab-item :: Pip + PyPI (recommented )
23+ .. md-tab-item :: Pip + PyPI (recommended )
2424
2525 .. code-block :: console
2626
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ def validate(
1515 * args : Any ,
1616 ** kwargs : Any
1717) -> None :
18+ """
19+ Validate an instance against a given schema using the specified validator class.
20+ """
1821 schema_dict = cast (dict [str , Any ], schema )
1922 cls .check_schema (schema_dict )
2023 validator = cls (schema_dict , * args , ** kwargs )
Original file line number Diff line number Diff line change 1- from unittest import TestCase
1+ import pytest
22
33from openapi_schema_validator import validate
44
55
6- class ValidateTest (TestCase ):
7- def test_validate_does_not_mutate_schema_adding_nullable_key (self ):
8- schema = {
9- "type" : "object" ,
10- "properties" : {
11- "email" : {"type" : "string" },
12- "enabled" : {
13- "type" : "boolean" ,
14- },
6+ @pytest .fixture (scope = "function" )
7+ def schema ():
8+ return {
9+ "type" : "object" ,
10+ "properties" : {
11+ "email" : {"type" : "string" },
12+ "enabled" : {
13+ "type" : "boolean" ,
1514 },
16- "example" : {"enabled" : False , "email" : "foo@bar.com" },
17- }
15+ },
16+ "example" : {"enabled" : False , "email" : "foo@bar.com" },
17+ }
1818
19- validate ({"email" : "foo@bar.com" }, schema )
2019
21- self .assertTrue ("nullable" not in schema ["properties" ]["email" ].keys ())
20+ def test_validate_does_not_add_nullable_to_schema (schema ):
21+ """
22+ Verify that calling validate does not add the 'nullable' key to the schema
23+ """
24+ validate ({"email" : "foo@bar.com" }, schema )
25+ assert "nullable" not in schema ["properties" ]["email" ].keys ()
26+
27+
28+ def test_validate_does_not_mutate_schema (schema ):
29+ """
30+ Verify that calling validate does not mutate the schema
31+ """
32+ original_schema = schema .copy ()
33+ validate ({"email" : "foo@bar.com" }, schema )
34+ assert schema == original_schema
You can’t perform that action at this time.
0 commit comments