1
1
import pathlib
2
+ from urllib .parse import ParseResult
2
3
3
4
import httpcore
4
5
import jinja2
@@ -167,7 +168,7 @@ def test__get_document_url_and_path(self, mocker):
167
168
loads .assert_not_called ()
168
169
169
170
def test__get_document_bad_url (self , mocker ):
170
- get = mocker .patch ("httpx.get" , side_effect = httpcore . NetworkError )
171
+ get = mocker .patch ("httpx.get" )
171
172
Path = mocker .patch ("openapi_python_client.Path" )
172
173
loads = mocker .patch ("yaml.safe_load" )
173
174
@@ -177,7 +178,7 @@ def test__get_document_bad_url(self, mocker):
177
178
result = _get_document (url = url , path = None )
178
179
179
180
assert result == GeneratorError (header = "Could not get OpenAPI document from provided URL" )
180
- get .assert_called_once_with ( url )
181
+ get .assert_not_called ( )
181
182
Path .assert_not_called ()
182
183
loads .assert_not_called ()
183
184
@@ -188,7 +189,7 @@ def test__get_document_url_no_path(self, mocker):
188
189
189
190
from openapi_python_client import _get_document
190
191
191
- url = mocker . MagicMock ()
192
+ url = "http://localhost/"
192
193
_get_document (url = url , path = None )
193
194
194
195
get .assert_called_once_with (url )
@@ -198,28 +199,30 @@ def test__get_document_url_no_path(self, mocker):
198
199
def test__get_document_path_no_url (self , mocker ):
199
200
get = mocker .patch ("httpx.get" )
200
201
loads = mocker .patch ("yaml.safe_load" )
202
+ mocker .patch ("openapi_python_client.resolver.schema_resolver.SchemaResolver._isapath" , return_value = True )
201
203
202
204
from openapi_python_client import _get_document
203
205
204
206
path = mocker .MagicMock ()
205
207
_get_document (url = None , path = path )
206
208
207
209
get .assert_not_called ()
208
- path .read_bytes .assert_called_once ()
209
- loads .assert_called_once_with (path .read_bytes ())
210
+ path .absolute (). read_bytes .assert_called_once ()
211
+ loads .assert_called_once_with (path .absolute (). read_bytes ())
210
212
211
213
def test__get_document_bad_yaml (self , mocker ):
212
214
get = mocker .patch ("httpx.get" )
213
215
loads = mocker .patch ("yaml.safe_load" , side_effect = yaml .YAMLError )
216
+ mocker .patch ("openapi_python_client.resolver.schema_resolver.SchemaResolver._isapath" , return_value = True )
214
217
215
218
from openapi_python_client import _get_document
216
219
217
220
path = mocker .MagicMock ()
218
221
result = _get_document (url = None , path = path )
219
222
220
223
get .assert_not_called ()
221
- path .read_bytes .assert_called_once ()
222
- loads .assert_called_once_with (path .read_bytes ())
224
+ path .absolute (). read_bytes .assert_called_once ()
225
+ loads .assert_called_once_with (path .absolute (). read_bytes ())
223
226
assert result == GeneratorError (header = "Invalid YAML from provided source" )
224
227
225
228
0 commit comments