@@ -343,55 +343,82 @@ def test__build_api(self, mocker):
343
343
openapi .endpoint_collections_by_tag = {tag_1 : collection_1 , tag_2 : collection_2 }
344
344
project = _Project (openapi = openapi )
345
345
project .package_dir = mocker .MagicMock ()
346
+ api_errors = mocker .MagicMock (autospec = pathlib .Path )
346
347
client_path = mocker .MagicMock ()
347
348
api_init = mocker .MagicMock (autospec = pathlib .Path )
348
- api_errors = mocker .MagicMock (autospec = pathlib .Path )
349
349
collection_1_path = mocker .MagicMock (autospec = pathlib .Path )
350
350
collection_2_path = mocker .MagicMock (autospec = pathlib .Path )
351
+ async_api_init = mocker .MagicMock (autospec = pathlib .Path )
352
+ async_collection_1_path = mocker .MagicMock (autospec = pathlib .Path )
353
+ async_collection_2_path = mocker .MagicMock (autospec = pathlib .Path )
351
354
api_paths = {
352
355
"__init__.py" : api_init ,
353
- "errors.py" : api_errors ,
354
356
f"{ tag_1 } .py" : collection_1_path ,
355
357
f"{ tag_2 } .py" : collection_2_path ,
356
358
}
359
+ async_api_paths = {
360
+ "__init__.py" : async_api_init ,
361
+ f"{ tag_1 } .py" : async_collection_1_path ,
362
+ f"{ tag_2 } .py" : async_collection_2_path ,
363
+ }
357
364
api_dir = mocker .MagicMock (autospec = pathlib .Path )
358
365
api_dir .__truediv__ .side_effect = lambda x : api_paths [x ]
366
+ async_api_dir = mocker .MagicMock (autospec = pathlib .Path )
367
+ async_api_dir .__truediv__ .side_effect = lambda x : async_api_paths [x ]
368
+
359
369
package_paths = {
360
370
"client.py" : client_path ,
361
371
"api" : api_dir ,
372
+ "async_api" : async_api_dir ,
373
+ "errors.py" : api_errors ,
362
374
}
363
375
project .package_dir .__truediv__ .side_effect = lambda x : package_paths [x ]
364
376
client_template = mocker .MagicMock (autospec = Template )
365
377
errors_template = mocker .MagicMock (autospec = Template )
366
378
endpoint_template = mocker .MagicMock (autospec = Template )
379
+ async_endpoint_template = mocker .MagicMock (autospec = Template )
367
380
templates = {
368
381
"client.pyi" : client_template ,
369
382
"errors.pyi" : errors_template ,
370
383
"endpoint_module.pyi" : endpoint_template ,
384
+ "async_endpoint_module.pyi" : async_endpoint_template ,
371
385
}
372
386
mocker .patch .object (project .env , "get_template" , autospec = True , side_effect = lambda x : templates [x ])
373
387
endpoint_renders = {
374
388
collection_1 : mocker .MagicMock (),
375
389
collection_2 : mocker .MagicMock (),
376
390
}
377
391
endpoint_template .render .side_effect = lambda collection : endpoint_renders [collection ]
392
+ async_endpoint_renders = {
393
+ collection_1 : mocker .MagicMock (),
394
+ collection_2 : mocker .MagicMock (),
395
+ }
396
+ async_endpoint_template .render .side_effect = lambda collection : async_endpoint_renders [collection ]
378
397
379
398
project ._build_api ()
380
399
381
400
project .package_dir .__truediv__ .assert_has_calls ([mocker .call (key ) for key in package_paths ])
382
401
project .env .get_template .assert_has_calls ([mocker .call (key ) for key in templates ])
383
402
client_template .render .assert_called_once ()
384
403
client_path .write_text .assert_called_once_with (client_template .render ())
385
- api_dir .mkdir .assert_called_once ()
386
- api_dir .__truediv__ .assert_has_calls ([mocker .call (key ) for key in api_paths ])
387
- api_init .write_text .assert_called_once_with ('""" Contains all methods for accessing the API """' )
388
404
errors_template .render .assert_called_once ()
389
405
api_errors .write_text .assert_called_once_with (errors_template .render ())
406
+ api_dir .mkdir .assert_called_once ()
407
+ api_dir .__truediv__ .assert_has_calls ([mocker .call (key ) for key in api_paths ])
408
+ api_init .write_text .assert_called_once_with ('""" Contains synchronous methods for accessing the API """' )
390
409
endpoint_template .render .assert_has_calls (
391
410
[mocker .call (collection = collection_1 ), mocker .call (collection = collection_2 )]
392
411
)
393
412
collection_1_path .write_text .assert_called_once_with (endpoint_renders [collection_1 ])
394
413
collection_2_path .write_text .assert_called_once_with (endpoint_renders [collection_2 ])
414
+ async_api_dir .mkdir .assert_called_once ()
415
+ async_api_dir .__truediv__ .assert_has_calls ([mocker .call (key ) for key in async_api_paths ])
416
+ async_api_init .write_text .assert_called_once_with ('""" Contains async methods for accessing the API """' )
417
+ async_endpoint_template .render .assert_has_calls (
418
+ [mocker .call (collection = collection_1 ), mocker .call (collection = collection_2 )]
419
+ )
420
+ async_collection_1_path .write_text .assert_called_once_with (async_endpoint_renders [collection_1 ])
421
+ async_collection_2_path .write_text .assert_called_once_with (async_endpoint_renders [collection_2 ])
395
422
396
423
397
424
def test__reformat (mocker ):
0 commit comments