@@ -25,6 +25,25 @@ def test__get_project_for_url_or_path(mocker):
25
25
assert project == _Project ()
26
26
27
27
28
+ def test__get_project_for_url_or_path_generator_error (mocker ):
29
+ data_dict = mocker .MagicMock ()
30
+ _get_document = mocker .patch ("openapi_python_client._get_document" , return_value = data_dict )
31
+ error = GeneratorError ()
32
+ from_dict = mocker .patch ("openapi_python_client.parser.GeneratorData.from_dict" , return_value = error )
33
+ _Project = mocker .patch ("openapi_python_client._Project" )
34
+ url = mocker .MagicMock ()
35
+ path = mocker .MagicMock ()
36
+
37
+ from openapi_python_client import _get_project_for_url_or_path
38
+
39
+ project = _get_project_for_url_or_path (url = url , path = path )
40
+
41
+ _get_document .assert_called_once_with (url = url , path = path )
42
+ from_dict .assert_called_once_with (data_dict )
43
+ _Project .assert_not_called ()
44
+ assert project == error
45
+
46
+
28
47
def test_create_new_client (mocker ):
29
48
project = mocker .MagicMock ()
30
49
_get_project_for_url_or_path = mocker .patch (
@@ -35,10 +54,27 @@ def test_create_new_client(mocker):
35
54
36
55
from openapi_python_client import create_new_client
37
56
38
- create_new_client (url = url , path = path )
57
+ result = create_new_client (url = url , path = path )
39
58
40
59
_get_project_for_url_or_path .assert_called_once_with (url = url , path = path )
41
60
project .build .assert_called_once ()
61
+ assert result == project .build .return_value
62
+
63
+
64
+ def test_create_new_client_project_error (mocker ):
65
+ error = GeneratorError ()
66
+ _get_project_for_url_or_path = mocker .patch (
67
+ "openapi_python_client._get_project_for_url_or_path" , return_value = error
68
+ )
69
+ url = mocker .MagicMock ()
70
+ path = mocker .MagicMock ()
71
+
72
+ from openapi_python_client import create_new_client
73
+
74
+ result = create_new_client (url = url , path = path )
75
+
76
+ _get_project_for_url_or_path .assert_called_once_with (url = url , path = path )
77
+ assert result == [error ]
42
78
43
79
44
80
def test_update_existing_client (mocker ):
@@ -51,10 +87,27 @@ def test_update_existing_client(mocker):
51
87
52
88
from openapi_python_client import update_existing_client
53
89
54
- update_existing_client (url = url , path = path )
90
+ result = update_existing_client (url = url , path = path )
55
91
56
92
_get_project_for_url_or_path .assert_called_once_with (url = url , path = path )
57
93
project .update .assert_called_once ()
94
+ assert result == project .update .return_value
95
+
96
+
97
+ def test_update_existing_client_project_error (mocker ):
98
+ error = GeneratorError ()
99
+ _get_project_for_url_or_path = mocker .patch (
100
+ "openapi_python_client._get_project_for_url_or_path" , return_value = error
101
+ )
102
+ url = mocker .MagicMock ()
103
+ path = mocker .MagicMock ()
104
+
105
+ from openapi_python_client import update_existing_client
106
+
107
+ result = update_existing_client (url = url , path = path )
108
+
109
+ _get_project_for_url_or_path .assert_called_once_with (url = url , path = path )
110
+ assert result == [error ]
58
111
59
112
60
113
class TestGetJson :
0 commit comments