22
33import pytest
44
5- from ninja import NinjaAPI , Schema
5+ from ninja import Field , NinjaAPI , Schema
66from ninja .patch_dict import PatchDict
77from ninja .testing import TestClient
88
@@ -15,6 +15,7 @@ class SomeSchema(Schema):
1515 name : str
1616 age : int
1717 category : Optional [str ] = None
18+ identifier : str = Field (max_length = 32 )
1819
1920
2021class OtherSchema (SomeSchema ):
@@ -47,6 +48,11 @@ def test_patch_calls(input: dict, output: dict):
4748 assert response .json () == {"payload" : output , "type" : "<class 'dict'>" }
4849
4950
51+ def test_patch_calls_bad_request ():
52+ response = client .patch ("/patch" , json = {"identifier" : "0" * 100 })
53+ assert response .status_code == 422
54+
55+
5056def test_schema ():
5157 "Checking that json schema properties are all optional"
5258 schema = api .get_openapi_schema ()
@@ -66,6 +72,13 @@ def test_schema():
6672 "anyOf" : [{"type" : "string" }, {"type" : "null" }],
6773 "title" : "Category" ,
6874 },
75+ "identifier" : {
76+ "anyOf" : [
77+ {"maxLength" : 32 , "type" : "string" },
78+ {"type" : "null" },
79+ ],
80+ "title" : "Identifier" ,
81+ },
6982 },
7083 }
7184
@@ -93,6 +106,13 @@ def test_inherited_schema():
93106 "anyOf" : [{"type" : "integer" }, {"type" : "null" }],
94107 "title" : "Age" ,
95108 },
109+ "identifier" : {
110+ "anyOf" : [
111+ {"maxLength" : 32 , "type" : "string" },
112+ {"type" : "null" },
113+ ],
114+ "title" : "Identifier" ,
115+ },
96116 "other" : {
97117 "anyOf" : [{"type" : "string" }, {"type" : "null" }],
98118 "title" : "Other" ,
0 commit comments