2525    EsAsyncAggregationClient ,
2626)
2727from  stac_fastapi .core .route_dependencies  import  get_route_dependencies 
28+ from  stac_fastapi .core .rate_limit  import  setup_rate_limit 
2829
2930if  os .getenv ("BACKEND" , "elasticsearch" ).lower () ==  "opensearch" :
3031    from  stac_fastapi .opensearch .config  import  AsyncOpensearchSettings  as  AsyncSettings 
@@ -223,7 +224,56 @@ async def app():
223224
224225    post_request_model  =  create_post_request_model (search_extensions )
225226
226-     return  StacApi (
227+     app  =  StacApi (
228+         settings = settings ,
229+         client = CoreClient (
230+             database = database ,
231+             session = None ,
232+             extensions = extensions ,
233+             post_request_model = post_request_model ,
234+         ),
235+         extensions = extensions ,
236+         search_get_request_model = create_get_request_model (search_extensions ),
237+         search_post_request_model = post_request_model ,
238+     ).app 
239+ 
240+     return  app 
241+ 
242+ 
243+ @pytest_asyncio .fixture (scope = "function" ) 
244+ async  def  app_rate_limit (monkeypatch ):
245+     monkeypatch .setenv ("STAC_FASTAPI_RATE_LIMIT" , "2/minute" )
246+     
247+     settings  =  AsyncSettings ()
248+     
249+     aggregation_extension  =  AggregationExtension (
250+         client = EsAsyncAggregationClient (
251+             database = database , session = None , settings = settings 
252+         )
253+     )
254+     aggregation_extension .POST  =  EsAggregationExtensionPostRequest 
255+     aggregation_extension .GET  =  EsAggregationExtensionGetRequest 
256+ 
257+     search_extensions  =  [
258+         TransactionExtension (
259+             client = TransactionsClient (
260+                 database = database , session = None , settings = settings 
261+             ),
262+             settings = settings ,
263+         ),
264+         SortExtension (),
265+         FieldsExtension (),
266+         QueryExtension (),
267+         TokenPaginationExtension (),
268+         FilterExtension (),
269+         FreeTextExtension (),
270+     ]
271+ 
272+     extensions  =  [aggregation_extension ] +  search_extensions 
273+ 
274+     post_request_model  =  create_post_request_model (search_extensions )
275+ 
276+     app  =  StacApi (
227277        settings = settings ,
228278        client = CoreClient (
229279            database = database ,
@@ -236,6 +286,12 @@ async def app():
236286        search_post_request_model = post_request_model ,
237287    ).app 
238288
289+     # Set up rate limit 
290+     setup_rate_limit (app )
291+ 
292+     return  app 
293+ 
294+ 
239295
240296@pytest_asyncio .fixture (scope = "session" ) 
241297async  def  app_client (app ):
@@ -246,6 +302,15 @@ async def app_client(app):
246302        yield  c 
247303
248304
305+ @pytest_asyncio .fixture (scope = "function" ) 
306+ async  def  app_client_rate_limit (app_rate_limit ):
307+     await  create_index_templates ()
308+     await  create_collection_index ()
309+ 
310+     async  with  AsyncClient (app = app_rate_limit , base_url = "http://test-server" ) as  c :
311+         yield  c 
312+ 
313+ 
249314@pytest_asyncio .fixture (scope = "session" ) 
250315async  def  app_basic_auth ():
251316
0 commit comments