7
7
8
8
from openapi_python_client import Config , ErrorLevel , GeneratorError , Project
9
9
10
+ default_http_timeout = Config .schema ()["properties" ]["http_timeout" ]["default" ]
11
+
10
12
11
13
def test__get_project_for_url_or_path (mocker ):
12
14
data_dict = mocker .MagicMock ()
@@ -17,12 +19,13 @@ def test__get_project_for_url_or_path(mocker):
17
19
url = mocker .MagicMock ()
18
20
path = mocker .MagicMock ()
19
21
config = mocker .MagicMock ()
22
+ config .http_timeout = default_http_timeout
20
23
21
24
from openapi_python_client import MetaType , _get_project_for_url_or_path
22
25
23
26
project = _get_project_for_url_or_path (url = url , path = path , meta = MetaType .POETRY , config = config )
24
27
25
- _get_document .assert_called_once_with (url = url , path = path )
28
+ _get_document .assert_called_once_with (url = url , path = path , timeout = default_http_timeout )
26
29
from_dict .assert_called_once_with (data_dict , config = config )
27
30
_Project .assert_called_once_with (
28
31
openapi = openapi , custom_template_path = None , meta = MetaType .POETRY , file_encoding = "utf-8" , config = config
@@ -39,12 +42,13 @@ def test__get_project_for_url_or_path_generator_error(mocker):
39
42
url = mocker .MagicMock ()
40
43
path = mocker .MagicMock ()
41
44
config = mocker .MagicMock ()
45
+ config .http_timeout = default_http_timeout
42
46
43
47
from openapi_python_client import MetaType , _get_project_for_url_or_path
44
48
45
49
project = _get_project_for_url_or_path (url = url , path = path , meta = MetaType .POETRY , config = config )
46
50
47
- _get_document .assert_called_once_with (url = url , path = path )
51
+ _get_document .assert_called_once_with (url = url , path = path , timeout = default_http_timeout )
48
52
from_dict .assert_called_once_with (data_dict , config = config )
49
53
_Project .assert_not_called ()
50
54
assert project == error
@@ -62,7 +66,7 @@ def test__get_project_for_url_or_path_document_error(mocker):
62
66
63
67
project = _get_project_for_url_or_path (url = url , path = path , meta = MetaType .POETRY , config = Config ())
64
68
65
- _get_document .assert_called_once_with (url = url , path = path )
69
+ _get_document .assert_called_once_with (url = url , path = path , timeout = default_http_timeout )
66
70
from_dict .assert_not_called ()
67
71
assert project == error
68
72
@@ -153,7 +157,7 @@ def test__get_document_no_url_or_path(self, mocker):
153
157
154
158
from openapi_python_client import _get_document
155
159
156
- result = _get_document (url = None , path = None )
160
+ result = _get_document (url = None , path = None , timeout = default_http_timeout )
157
161
158
162
assert result == GeneratorError (header = "No URL or Path provided" )
159
163
get .assert_not_called ()
@@ -167,7 +171,7 @@ def test__get_document_url_and_path(self, mocker):
167
171
168
172
from openapi_python_client import _get_document
169
173
170
- result = _get_document (url = mocker .MagicMock (), path = mocker .MagicMock ())
174
+ result = _get_document (url = mocker .MagicMock (), path = mocker .MagicMock (), timeout = default_http_timeout )
171
175
172
176
assert result == GeneratorError (header = "Provide URL or Path, not both." )
173
177
get .assert_not_called ()
@@ -182,10 +186,10 @@ def test__get_document_bad_url(self, mocker):
182
186
from openapi_python_client import _get_document
183
187
184
188
url = mocker .MagicMock ()
185
- result = _get_document (url = url , path = None )
189
+ result = _get_document (url = url , path = None , timeout = default_http_timeout )
186
190
187
191
assert result == GeneratorError (header = "Could not get OpenAPI document from provided URL" )
188
- get .assert_called_once_with (url )
192
+ get .assert_called_once_with (url , timeout = default_http_timeout )
189
193
_Path .assert_not_called ()
190
194
loads .assert_not_called ()
191
195
@@ -197,9 +201,9 @@ def test__get_document_url_no_path(self, mocker):
197
201
from openapi_python_client import _get_document
198
202
199
203
url = "test"
200
- _get_document (url = url , path = None )
204
+ _get_document (url = url , path = None , timeout = default_http_timeout )
201
205
202
- get .assert_called_once_with (url )
206
+ get .assert_called_once_with (url , timeout = default_http_timeout )
203
207
_Path .assert_not_called ()
204
208
loads .assert_called_once_with (get ().content )
205
209
@@ -211,7 +215,7 @@ def test__get_document_path_no_url(self, tmp_path, mocker):
211
215
212
216
from openapi_python_client import _get_document
213
217
214
- _get_document (url = None , path = path )
218
+ _get_document (url = None , path = path , timeout = default_http_timeout )
215
219
216
220
get .assert_not_called ()
217
221
loads .assert_called_once_with (b"some test data" )
@@ -222,7 +226,7 @@ def test__get_document_bad_yaml(self, mocker, tmp_path):
222
226
223
227
path = tmp_path / "test.yaml"
224
228
path .write_text ("'" )
225
- result = _get_document (url = None , path = path )
229
+ result = _get_document (url = None , path = path , timeout = default_http_timeout )
226
230
227
231
get .assert_not_called ()
228
232
assert isinstance (result , GeneratorError )
@@ -241,7 +245,7 @@ class FakeResponse:
241
245
from openapi_python_client import _get_document
242
246
243
247
url = mocker .MagicMock ()
244
- result = _get_document (url = url , path = None )
248
+ result = _get_document (url = url , path = None , timeout = default_http_timeout )
245
249
246
250
get .assert_called_once ()
247
251
json_loads .assert_called_once_with (FakeResponse .content .decode ())
@@ -258,7 +262,7 @@ class FakeResponse:
258
262
from openapi_python_client import _get_document
259
263
260
264
url = mocker .MagicMock ()
261
- result = _get_document (url = url , path = None )
265
+ result = _get_document (url = url , path = None , timeout = default_http_timeout )
262
266
263
267
get .assert_called_once ()
264
268
assert result == GeneratorError (
0 commit comments