Skip to content

Commit 8d61c1d

Browse files
fix: test coverage (openapi_python_client/cli.py)
1 parent d63e579 commit 8d61c1d

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

tests/test_cli.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,26 @@ def test_generate_meta(self, _create_new_client):
115115

116116
def test_generate_encoding(self, _create_new_client):
117117
path = "cool/path"
118-
encoding = "utf-8"
118+
file_encoding = "utf-8"
119119
from openapi_python_client.cli import MetaType, app
120120

121-
result = runner.invoke(app, ["generate", f"--path={path}", f"--file-encoding={encoding}"])
121+
result = runner.invoke(app, ["generate", f"--path={path}", f"--file-encoding={file_encoding}"])
122122

123123
assert result.exit_code == 0
124124
_create_new_client.assert_called_once_with(
125125
url=None, path=Path(path), custom_template_path=None, meta=MetaType.POETRY, file_encoding="utf-8"
126126
)
127127

128+
def test_generate_encoding_errors(self, _create_new_client):
129+
path = "cool/path"
130+
file_encoding = "error-file-encoding"
131+
from openapi_python_client.cli import MetaType, app
132+
133+
result = runner.invoke(app, ["generate", f"--path={path}", f"--file-encoding={file_encoding}"])
134+
135+
assert result.exit_code == 1
136+
assert result.output == "Unknown encoding : {}\n".format(file_encoding)
137+
128138
def test_generate_handle_errors(self, _create_new_client):
129139
_create_new_client.return_value = [GeneratorError(detail="this is a message")]
130140
path = "cool/path"
@@ -207,3 +217,25 @@ def test_update_path(self, _update_existing_client):
207217
_update_existing_client.assert_called_once_with(
208218
url=None, path=Path(path), custom_template_path=None, meta=MetaType.POETRY, file_encoding="utf-8"
209219
)
220+
221+
def test_update_encoding(self, _update_existing_client):
222+
path = "cool/path"
223+
file_encoding = "utf-8"
224+
from openapi_python_client.cli import MetaType, app
225+
226+
result = runner.invoke(app, ["update", f"--path={path}", f"--file-encoding={file_encoding}"])
227+
228+
assert result.exit_code == 0
229+
_update_existing_client.assert_called_once_with(
230+
url=None, path=Path(path), custom_template_path=None, meta=MetaType.POETRY, file_encoding="utf-8"
231+
)
232+
233+
def test_update_encoding_errors(self, _update_existing_client):
234+
path = "cool/path"
235+
file_encoding = "error-file-encoding"
236+
from openapi_python_client.cli import MetaType, app
237+
238+
result = runner.invoke(app, ["update", f"--path={path}", f"--file-encoding={file_encoding}"])
239+
240+
assert result.exit_code == 1
241+
assert result.output == "Unknown encoding : {}\n".format(file_encoding)

0 commit comments

Comments
 (0)