Repository navigation
Expand file tree
/
Copy pathtest_cli.py
More file actions
129 lines (83 loc) · 4.08 KB
/
Copy pathtest_cli.py
File metadata and controls
129 lines (83 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from pathlib import PosixPath
from unittest.mock import MagicMock
import pytest
from typer.testing import CliRunner
runner = CliRunner()
def test_version(mocker):
generate = mocker.patch("openapi_python_client.cli.generate")
from openapi_python_client.cli import app
result = runner.invoke(app, ["--version", "generate"])
generate.assert_not_called()
assert result.exit_code == 0
assert "openapi-python-client version: " in result.stdout
@pytest.fixture
def _create_new_client(mocker) -> MagicMock:
return mocker.patch("openapi_python_client.create_new_client")
def test_config(mocker, _create_new_client):
load_config = mocker.patch("openapi_python_client.load_config")
from openapi_python_client.cli import app
config_path = "config/path"
path = "cool/path"
result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={path}"], catch_exceptions=False)
assert result.exit_code == 0
load_config.assert_called_once_with(path=PosixPath(config_path))
_create_new_client.assert_called_once_with(url=None, path=PosixPath(path))
def test_bad_config(mocker, _create_new_client):
load_config = mocker.patch("openapi_python_client.load_config", side_effect=ValueError("Bad Config"))
from openapi_python_client.cli import app
config_path = "config/path"
path = "cool/path"
result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={path}"])
assert result.exit_code == 2
assert "Unable to parse config" in result.stdout
load_config.assert_called_once_with(path=PosixPath(config_path))
_create_new_client.assert_not_called()
class TestGenerate:
def test_generate_no_params(self, _create_new_client):
from openapi_python_client.cli import app
result = runner.invoke(app, ["generate"])
assert result.exit_code == 1, result.output
_create_new_client.assert_not_called()
def test_generate_url_and_path(self, _create_new_client):
from openapi_python_client.cli import app
result = runner.invoke(app, ["generate", "--path=blah", "--url=otherblah"])
assert result.exit_code == 1
_create_new_client.assert_not_called()
def test_generate_url(self, _create_new_client):
url = "cool.url"
from openapi_python_client.cli import app
result = runner.invoke(app, ["generate", f"--url={url}"])
assert result.exit_code == 0
_create_new_client.assert_called_once_with(url=url, path=None)
def test_generate_path(self, _create_new_client):
path = "cool/path"
from openapi_python_client.cli import app
result = runner.invoke(app, ["generate", f"--path={path}"])
assert result.exit_code == 0
_create_new_client.assert_called_once_with(url=None, path=PosixPath(path))
@pytest.fixture
def _update_existing_client(mocker):
return mocker.patch("openapi_python_client.update_existing_client")
class TestUpdate:
def test_update_no_params(self, _update_existing_client):
from openapi_python_client.cli import app
result = runner.invoke(app, ["update"])
assert result.exit_code == 1
_update_existing_client.assert_not_called()
def test_update_url_and_path(self, _update_existing_client):
from openapi_python_client.cli import app
result = runner.invoke(app, ["update", "--path=blah", "--url=otherblah"])
assert result.exit_code == 1
_update_existing_client.assert_not_called()
def test_update_url(self, _update_existing_client):
url = "cool.url"
from openapi_python_client.cli import app
result = runner.invoke(app, ["update", f"--url={url}"])
assert result.exit_code == 0
_update_existing_client.assert_called_once_with(url=url, path=None)
def test_update_path(self, _update_existing_client):
path = "cool/path"
from openapi_python_client.cli import app
result = runner.invoke(app, ["update", f"--path={path}"])
assert result.exit_code == 0
_update_existing_client.assert_called_once_with(url=None, path=PosixPath(path))