22from copy import deepcopy
33from itertools import chain , zip_longest
44from json import dumps
5- from typing import Dict , List , Type
5+ from typing import Dict , List , Optional , Type
66from uuid import UUID , uuid4
77
88from fastapi import FastAPI , status
@@ -2050,19 +2050,13 @@ def _refresh_caches(self) -> None:
20502050
20512051 RoutersJSONAPI .all_jsonapi_routers = all_jsonapi_routers
20522052
2053- def _clear_cache (self ):
2054- SchemaBuilder .object_schemas_cache = {}
2055- SchemaBuilder .relationship_schema_cache = {}
2056- SchemaBuilder .base_jsonapi_object_schemas_cache = {}
2057- RoutersJSONAPI .all_jsonapi_routers = {}
2058-
2059- def build_app (self , schema ) -> FastAPI :
2053+ def build_app (self , schema , resource_type : Optional [str ] = None ) -> FastAPI :
20602054 return build_app_custom (
20612055 model = User ,
20622056 schema = schema ,
2063- schema_in_post = schema ,
2064- schema_in_patch = schema ,
2065- resource_type = self .resource_type ,
2057+ # schema_in_post=schema,
2058+ # schema_in_patch=schema,
2059+ resource_type = resource_type or self .resource_type ,
20662060 )
20672061
20682062 def inherit (self , schema : Type [BaseModel ]) -> Type [BaseModel ]:
@@ -2076,9 +2070,11 @@ async def execute_request_and_check_response(
20762070 app : FastAPI ,
20772071 body : Dict ,
20782072 expected_detail : str ,
2073+ resource_type : Optional [str ] = None ,
20792074 ):
2075+ resource_type = resource_type or self .resource_type
20802076 async with AsyncClient (app = app , base_url = "http://test" ) as client :
2081- url = app .url_path_for (f"get_{ self . resource_type } _list" )
2077+ url = app .url_path_for (f"get_{ resource_type } _list" )
20822078 res = await client .post (url , json = body )
20832079 assert res .status_code == status .HTTP_400_BAD_REQUEST , res .text
20842080 assert res .json () == {
@@ -2093,7 +2089,6 @@ async def execute_request_and_check_response(
20932089 ],
20942090 },
20952091 }
2096- self ._clear_cache ()
20972092
20982093 async def execute_request_twice_and_check_response (
20992094 self ,
@@ -2104,15 +2099,17 @@ async def execute_request_twice_and_check_response(
21042099 """
21052100 Makes two requests for check schema inheritance
21062101 """
2107- app_1 = self .build_app (schema )
2108- self ._clear_cache ()
2109- app_2 = self .build_app (self .inherit (schema ))
2102+ resource_type_1 = self .resource_type + fake .word ()
2103+ app_1 = self .build_app (schema , resource_type = resource_type_1 )
2104+ resource_type_2 = self .resource_type + fake .word ()
2105+ app_2 = self .build_app (self .inherit (schema ), resource_type = resource_type_2 )
21102106
2111- for app in [app_1 , app_2 ]:
2107+ for app , resource_type in [( app_1 , resource_type_1 ), ( app_2 , resource_type_2 ) ]:
21122108 await self .execute_request_and_check_response (
21132109 app = app ,
21142110 body = body ,
21152111 expected_detail = expected_detail ,
2112+ resource_type = resource_type ,
21162113 )
21172114
21182115 async def test_field_validator_call (self ):
0 commit comments