Skip to content

Commit 4ef6032

Browse files
more fixturization.
Co-authored-by: Piotr Kaznowski <[email protected]>
1 parent 7a2f5b3 commit 4ef6032

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

tests/test_cli_website.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ def command():
2020
return "/usr/local/bin/uvicorn --uds $DOMAIN_SOCKET main:app"
2121

2222

23+
@pytest.fixture
24+
def mock_echo(mocker):
25+
return mocker.patch("cli.website.typer.echo")
26+
27+
28+
@pytest.fixture
29+
def mock_tabulate(mocker):
30+
return mocker.patch("cli.website.tabulate")
31+
32+
2333
@pytest.fixture
2434
def mock_website(mocker):
2535
return mocker.patch("cli.website.Website")
@@ -104,11 +114,9 @@ def test_create_with_domain_and_command_creates_it(mock_website):
104114
assert "All done!" in result.stdout
105115

106116

107-
def test_get_with_no_domain_lists_websites(mocker, mock_website, website_info):
117+
def test_get_with_no_domain_lists_websites(mock_echo, mock_tabulate, mock_website, website_info):
108118
second_website_info = {"domain_name": "blah.com", "enabled": False}
109119
mock_website.return_value.list.return_value = [website_info, second_website_info]
110-
mock_tabulate = mocker.patch("cli.website.tabulate")
111-
mock_echo = mocker.patch("cli.website.typer.echo")
112120

113121
result = runner.invoke(
114122
app,
@@ -130,10 +138,10 @@ def test_get_with_no_domain_lists_websites(mocker, mock_website, website_info):
130138
mock_echo.assert_called_once_with(mock_tabulate.return_value)
131139

132140

133-
def test_get_with_domain_gives_details_for_domain(mocker, mock_website, website_info, domain_name):
141+
def test_get_with_domain_gives_details_for_domain(
142+
mock_echo, mock_tabulate, mock_website, website_info, domain_name
143+
):
134144
mock_website.return_value.get.return_value = website_info
135-
mock_tabulate = mocker.patch("cli.website.tabulate")
136-
mock_echo = mocker.patch("cli.website.typer.echo")
137145

138146
result = runner.invoke(
139147
app,
@@ -161,7 +169,7 @@ def test_get_with_domain_gives_details_for_domain(mocker, mock_website, website_
161169

162170

163171
def test_get_with_domain_gives_details_for_domain_even_without_logfiles(
164-
mocker, domain_name, command, mock_website
172+
domain_name, command, mock_echo, mock_tabulate, mock_website
165173
):
166174
website_info = {
167175
"domain_name": domain_name,
@@ -180,8 +188,6 @@ def test_get_with_domain_gives_details_for_domain_even_without_logfiles(
180188
}
181189
}
182190
mock_website.return_value.get.return_value = website_info
183-
mock_tabulate = mocker.patch("cli.website.tabulate")
184-
mock_echo = mocker.patch("cli.website.typer.echo")
185191

186192
result = runner.invoke(
187193
app,
@@ -216,9 +222,8 @@ def test_reload_with_no_domain_barfs():
216222
assert "Missing option" in result.stdout
217223

218224

219-
def test_reload_with_domain_reloads(mocker, mock_website):
225+
def test_reload_with_domain_reloads(mocker, mock_echo, mock_website):
220226
mock_snakesay = mocker.patch("cli.website.snakesay")
221-
mock_echo = mocker.patch("cli.website.typer.echo")
222227

223228
result = runner.invoke(
224229
app,
@@ -246,9 +251,8 @@ def test_delete_with_no_domain_barfs():
246251
assert "Missing option" in result.stdout
247252

248253

249-
def test_delete_with_domain_deletes_it(mocker, mock_website):
254+
def test_delete_with_domain_deletes_it(mocker, mock_echo, mock_website):
250255
mock_snakesay = mocker.patch("cli.website.snakesay")
251-
mock_echo = mocker.patch("cli.website.typer.echo")
252256

253257
result = runner.invoke(
254258
app,

0 commit comments

Comments
 (0)