@@ -23,7 +23,7 @@ def test_get_auth_token_without_env(model_data_with_cleanup):
2323 _locals = locals ()
2424
2525 exec (
26- "from .test_result import *\n assert APIConfig.get_access_token() is None" ,
26+ "from .test_result import *\n assert APIConfig() .get_access_token() is None" ,
2727 globals (),
2828 _locals ,
2929 )
@@ -34,9 +34,10 @@ def test_set_auth_token():
3434
3535 _locals = locals ()
3636 program = """from .test_result import APIConfig
37- assert APIConfig.get_access_token() is None
38- APIConfig.set_access_token('foo_bar')
39- assert APIConfig.get_access_token() == 'foo_bar'
37+ api_config = APIConfig()
38+ assert api_config.get_access_token() is None
39+ api_config.set_access_token('foo_bar')
40+ assert api_config.get_access_token() == 'foo_bar'
4041 """
4142 exec (
4243 program ,
@@ -46,29 +47,40 @@ def test_set_auth_token():
4647
4748
4849@pytest .mark .parametrize (
49- "library, use_orjson" ,
50+ "library, use_orjson, custom_ip " ,
5051 [
51- (HTTPLibrary .httpx , False ),
52- (HTTPLibrary .requests , False ),
53- (HTTPLibrary .httpx , True ),
54- (HTTPLibrary .requests , True ),
55- (HTTPLibrary .aiohttp , True ),
56- (HTTPLibrary .aiohttp , False ),
52+ (HTTPLibrary .httpx , False , None ),
53+ (HTTPLibrary .requests , False , None ),
54+ (HTTPLibrary .httpx , True , None ),
55+ (HTTPLibrary .requests , True , None ),
56+ (HTTPLibrary .aiohttp , True , None ),
57+ (HTTPLibrary .aiohttp , False , None ),
58+ (HTTPLibrary .httpx , False , "http://localhost:5000" ),
59+ (HTTPLibrary .requests , False , "http://localhost:5000" ),
60+ (HTTPLibrary .httpx , True , "http://localhost:5000" ),
61+ (HTTPLibrary .requests , True , "http://localhost:5000" ),
62+ (HTTPLibrary .aiohttp , True , "http://localhost:5000" ),
63+ (HTTPLibrary .aiohttp , False , "http://localhost:5000" ),
5764 ],
5865)
5966@respx .mock
60- def test_generate_code (model_data_with_cleanup , library , use_orjson ):
67+ def test_generate_code (model_data_with_cleanup , library , use_orjson , custom_ip ):
6168 generate_data (test_data_path , test_result_path , library , use_orjson = use_orjson )
6269 result = generator (model_data_with_cleanup , library_config_dict [library ])
6370
71+ if custom_ip is not None :
72+ api_config_custom = result .api_config
73+ api_config_custom .base_url = custom_ip
74+ else :
75+ api_config_custom = result .api_config
76+
6477 # Testing root access
65- _locals = locals ()
66- root_route = respx .get (f"{ result .api_config .base_url } /" ).mock (
78+ root_route = respx .get (f"{ api_config_custom .base_url } /" ).mock (
6779 return_value = Response (
6880 status_code = 200 , content = json .dumps ({"message" : "Hello World" })
6981 )
7082 )
71- get_users_route = respx .get (f"{ result . api_config .base_url } /users" ).mock (
83+ get_users_route = respx .get (f"{ api_config_custom .base_url } /users" ).mock (
7284 return_value = Response (
7385 status_code = 200 ,
7486 content = json .dumps (
@@ -93,7 +105,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
93105 ),
94106 )
95107 )
96- get_user_route = respx .get (f"{ result . api_config .base_url } /users/{ 1 } " ).mock (
108+ get_user_route = respx .get (f"{ api_config_custom .base_url } /users/{ 1 } " ).mock (
97109 return_value = Response (
98110 status_code = 200 ,
99111 content = json .dumps (
@@ -108,7 +120,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
108120 ),
109121 )
110122 )
111- post_user_route = respx .post (f"{ result . api_config .base_url } /users" ).mock (
123+ post_user_route = respx .post (f"{ api_config_custom .base_url } /users" ).mock (
112124 return_value = Response (
113125 status_code = 201 ,
114126 content = json .dumps (
@@ -123,7 +135,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
123135 ),
124136 )
125137 )
126- update_user_route = respx .patch (f"{ result . api_config .base_url } /users/{ 1 } " ).mock (
138+ update_user_route = respx .patch (f"{ api_config_custom .base_url } /users/{ 1 } " ).mock (
127139 return_value = Response (
128140 status_code = 200 ,
129141 content = json .dumps (
@@ -137,11 +149,11 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
137149 ),
138150 )
139151 )
140- delete_user_route = respx .delete (f"{ result . api_config .base_url } /users/{ 1 } " ).mock (
152+ delete_user_route = respx .delete (f"{ api_config_custom .base_url } /users/{ 1 } " ).mock (
141153 return_value = Response (status_code = 204 , content = json .dumps (None ))
142154 )
143155
144- get_teams_route = respx .get (f"{ result . api_config .base_url } /teams" ).mock (
156+ get_teams_route = respx .get (f"{ api_config_custom .base_url } /teams" ).mock (
145157 return_value = Response (
146158 status_code = 200 ,
147159 content = orjson .dumps (
@@ -167,7 +179,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
167179 )
168180 )
169181
170- get_team_route = respx .get (f"{ result . api_config .base_url } /teams/{ 1 } " ).mock (
182+ get_team_route = respx .get (f"{ api_config_custom .base_url } /teams/{ 1 } " ).mock (
171183 return_value = Response (
172184 status_code = 200 ,
173185 content = orjson .dumps (
@@ -182,7 +194,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
182194 ),
183195 )
184196 )
185- post_team_route = respx .post (f"{ result . api_config .base_url } /teams" ).mock (
197+ post_team_route = respx .post (f"{ api_config_custom .base_url } /teams" ).mock (
186198 return_value = Response (
187199 status_code = 201 ,
188200 content = orjson .dumps (
@@ -198,7 +210,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
198210 )
199211 )
200212
201- update_team_route = respx .patch (f"{ result . api_config .base_url } /teams/{ 1 } " ).mock (
213+ update_team_route = respx .patch (f"{ api_config_custom .base_url } /teams/{ 1 } " ).mock (
202214 return_value = Response (
203215 status_code = 200 ,
204216 content = orjson .dumps (
@@ -214,15 +226,26 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
214226 )
215227 )
216228
217- delete_team_route = respx .delete (f"{ result . api_config .base_url } /teams/{ 1 } " ).mock (
229+ delete_team_route = respx .delete (f"{ api_config_custom .base_url } /teams/{ 1 } " ).mock (
218230 return_value = Response (status_code = 204 , content = json .dumps (None ))
219231 )
220232
221- exec_code_base = f"""from .test_result.services.general_service import *\n resp_result = root__get()\n assert isinstance(resp_result, RootResponse)"""
233+ passed_api_config = None
234+
235+
236+
237+ if custom_ip :
238+ from .test_result .api_config import APIConfig
239+ passed_api_config = APIConfig ()
240+ passed_api_config .base_path = custom_ip
241+
242+ _locals = locals ()
243+
244+ exec_code_base = f"""from .test_result.services.general_service import *\n resp_result = root__get(passed_api_config)\n assert isinstance(resp_result, RootResponse)"""
222245 exec (exec_code_base , globals (), _locals )
223246 assert root_route .called
224247
225- exec_code_base = f"try:\n \t from .test_result import *\n \t resp_result = get_users_users_get()\n except Exception as e:\n \t print(e)\n \t raise e"
248+ exec_code_base = f"try:\n \t from .test_result import *\n \t resp_result = get_users_users_get(passed_api_config )\n except Exception as e:\n \t print(e)\n \t raise e"
226249
227250 try :
228251 exec (exec_code_base , globals (), _locals )
@@ -250,7 +273,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
250273 exec (exec_code_base , globals (), _locals )
251274 assert get_users_route .called
252275
253- exec_code_base = f"from .test_result.services.general_service import *\n resp_result = get_user_users__user_id__get(1,'test')"
276+ exec_code_base = f"from .test_result.services.general_service import *\n resp_result = get_user_users__user_id__get(1,'test',passed_api_config )"
254277
255278 exec (exec_code_base , globals (), _locals )
256279
@@ -266,7 +289,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
266289 id = 1 ,
username = "user1" ,
email = "[email protected] " ,
password = "123456" ,
is_active = True 267290 )
268291
269- exec_code_base = f"from .test_result.services.general_service import *\n resp_result = create_user_users_post(User(**{ data } ))"
292+ exec_code_base = f"from .test_result.services.general_service import *\n resp_result = create_user_users_post(User(**{ data } ),passed_api_config )"
270293
271294 exec (exec_code_base , globals (), _locals )
272295
@@ -277,7 +300,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
277300 )
278301 assert post_user_route .called
279302
280- exec_code_base = f"from .test_result.services.general_service import *\n resp_result = update_user_users__user_id__patch(1, User(**{ data } ))"
303+ exec_code_base = f"from .test_result.services.general_service import *\n resp_result = update_user_users__user_id__patch(1, User(**{ data } ), passed_api_config )"
281304
282305 exec (exec_code_base , globals (), _locals )
283306
@@ -288,13 +311,13 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
288311 )
289312 assert update_user_route .called
290313
291- exec_code_base = f"from .test_result.services.general_service import *\n resp_result = delete_user_users__user_id__delete(1)"
314+ exec_code_base = f"from .test_result.services.general_service import *\n resp_result = delete_user_users__user_id__delete(1, passed_api_config )"
292315
293316 exec (exec_code_base , globals (), _locals )
294317
295318 assert delete_user_route .called
296319
297- exec_code_base = f"from .test_result.services.general_service import *\n resp_result = get_teams_teams_get()"
320+ exec_code_base = f"from .test_result.services.general_service import *\n resp_result = get_teams_teams_get(passed_api_config )"
298321
299322 exec (exec_code_base , globals (), _locals )
300323
@@ -315,7 +338,7 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
315338 )
316339 assert get_teams_route .called
317340
318- exec_code_base = f"from .test_result.services.general_service import *\n resp_result = get_team_teams__team_id__get(1)"
341+ exec_code_base = f"from .test_result.services.general_service import *\n resp_result = get_team_teams__team_id__get(1, passed_api_config )"
319342
320343 exec (exec_code_base , globals (), _locals )
321344 assert get_team_route .called
@@ -329,16 +352,16 @@ def test_generate_code(model_data_with_cleanup, library, use_orjson):
329352 updated_at = "" ,
330353 )
331354
332- exec_code_base = f"from .test_result.services.general_service import *\n from datetime import datetime\n resp_result = create_team_teams_post(Team(**{ data } ))"
355+ exec_code_base = f"from .test_result.services.general_service import *\n from datetime import datetime\n resp_result = create_team_teams_post(Team(**{ data } ), passed_api_config )"
333356
334357 exec (exec_code_base , globals (), _locals )
335358 assert post_team_route .called
336359
337- exec_code_base = f"from .test_result.services.general_service import *\n from datetime import datetime\n resp_result = update_team_teams__team_id__patch(1, Team(**{ data } ))"
360+ exec_code_base = f"from .test_result.services.general_service import *\n from datetime import datetime\n resp_result = update_team_teams__team_id__patch(1, Team(**{ data } ), passed_api_config )"
338361
339362 exec (exec_code_base , globals (), _locals )
340363 assert update_team_route .called
341364
342- exec_code_base = f"from .test_result.services.general_service import *\n resp_result = delete_team_teams__team_id__delete(1)"
365+ exec_code_base = f"from .test_result.services.general_service import *\n resp_result = delete_team_teams__team_id__delete(1, passed_api_config )"
343366
344367 exec (exec_code_base , globals (), _locals )
0 commit comments