1+ import pytest
2+
3+
14def test_main (mocker ):
25 data_dict = mocker .MagicMock ()
36 _get_json = mocker .patch ("openapi_python_client._get_json" , return_value = data_dict )
@@ -14,3 +17,61 @@ def test_main(mocker):
1417 _get_json .assert_called_once_with (url = url , path = path )
1518 from_dict .assert_called_once_with (data_dict )
1619 _build_project .assert_called_once_with (openapi = openapi )
20+
21+
22+ class TestGetJson :
23+ def test__get_json_no_url_or_path (self , mocker ):
24+ get = mocker .patch ("requests.get" )
25+ Path = mocker .patch ("pathlib.Path" )
26+ loads = mocker .patch ("json.loads" )
27+
28+ from openapi_python_client import _get_json
29+
30+ with pytest .raises (ValueError ):
31+ _get_json (url = None , path = None )
32+
33+ get .assert_not_called ()
34+ Path .assert_not_called ()
35+ loads .assert_not_called ()
36+
37+ def test__get_json_url_and_path (self , mocker ):
38+ get = mocker .patch ("requests.get" )
39+ Path = mocker .patch ("pathlib.Path" )
40+ loads = mocker .patch ("json.loads" )
41+
42+ from openapi_python_client import _get_json
43+
44+ with pytest .raises (ValueError ):
45+ _get_json (url = mocker .MagicMock (), path = mocker .MagicMock ())
46+
47+ get .assert_not_called ()
48+ Path .assert_not_called ()
49+ loads .assert_not_called ()
50+
51+ def test__get_json_url_no_path (self , mocker ):
52+ get = mocker .patch ("requests.get" )
53+ Path = mocker .patch ("pathlib.Path" )
54+ loads = mocker .patch ("json.loads" )
55+
56+ from openapi_python_client import _get_json
57+
58+ url = mocker .MagicMock ()
59+ _get_json (url = url , path = None )
60+
61+ get .assert_called_once_with (url )
62+ Path .assert_not_called ()
63+ loads .assert_called_once_with (get ().content )
64+
65+ def test__get_json_path_no_url (self , mocker ):
66+ get = mocker .patch ("requests.get" )
67+ Path = mocker .patch ("pathlib.Path" )
68+ loads = mocker .patch ("json.loads" )
69+
70+ from openapi_python_client import _get_json
71+
72+ path = mocker .MagicMock ()
73+ _get_json (url = None , path = path )
74+
75+ get .assert_not_called ()
76+ Path .assert_called_once_with (path )
77+ loads .assert_called_once_with (Path ().read_bytes ())
0 commit comments