diff --git a/tests/test_cli_website.py b/tests/test_cli_website.py index 0c0f4f5..77874ca 100644 --- a/tests/test_cli_website.py +++ b/tests/test_cli_website.py @@ -20,6 +20,11 @@ def command(): return "/usr/local/bin/uvicorn --uds $DOMAIN_SOCKET main:app" +@pytest.fixture +def mock_website(mocker): + return mocker.patch("cli.website.Website") + + @pytest.fixture def website_info(domain_name, command): return { @@ -80,8 +85,7 @@ def test_create_without_command_barfs(): assert "Missing option" in result.stdout -def test_create_with_domain_and_command_creates_it(mocker): - mock_website = mocker.patch("cli.website.Website") +def test_create_with_domain_and_command_creates_it(mock_website): result = runner.invoke( app, [ @@ -100,8 +104,7 @@ def test_create_with_domain_and_command_creates_it(mocker): assert "All done!" in result.stdout -def test_get_with_no_domain_lists_websites(mocker, website_info): - mock_website = mocker.patch("cli.website.Website") +def test_get_with_no_domain_lists_websites(mocker, mock_website, website_info): second_website_info = {"domain_name": "blah.com", "enabled": False} mock_website.return_value.list.return_value = [website_info, second_website_info] mock_tabulate = mocker.patch("cli.website.tabulate") @@ -127,8 +130,7 @@ def test_get_with_no_domain_lists_websites(mocker, website_info): mock_echo.assert_called_once_with(mock_tabulate.return_value) -def test_get_with_domain_gives_details_for_domain(mocker, website_info, domain_name): - mock_website = mocker.patch("cli.website.Website") +def test_get_with_domain_gives_details_for_domain(mocker, mock_website, website_info, domain_name): mock_website.return_value.get.return_value = website_info mock_tabulate = mocker.patch("cli.website.tabulate") mock_echo = mocker.patch("cli.website.typer.echo") @@ -159,7 +161,7 @@ def test_get_with_domain_gives_details_for_domain(mocker, website_info, domain_n def test_get_with_domain_gives_details_for_domain_even_without_logfiles( - mocker, domain_name, command + mocker, domain_name, command, mock_website ): website_info = { "domain_name": domain_name, @@ -177,7 +179,6 @@ def test_get_with_domain_gives_details_for_domain_even_without_logfiles( "id": 42 } } - mock_website = mocker.patch("cli.website.Website") mock_website.return_value.get.return_value = website_info mock_tabulate = mocker.patch("cli.website.tabulate") mock_echo = mocker.patch("cli.website.typer.echo") @@ -215,8 +216,7 @@ def test_reload_with_no_domain_barfs(): assert "Missing option" in result.stdout -def test_reload_with_domain_reloads(mocker): - mock_website = mocker.patch("cli.website.Website") +def test_reload_with_domain_reloads(mocker, mock_website): mock_snakesay = mocker.patch("cli.website.snakesay") mock_echo = mocker.patch("cli.website.typer.echo") @@ -246,8 +246,7 @@ def test_delete_with_no_domain_barfs(): assert "Missing option" in result.stdout -def test_delete_with_domain_deletes_it(mocker): - mock_website = mocker.patch("cli.website.Website") +def test_delete_with_domain_deletes_it(mocker, mock_website): mock_snakesay = mocker.patch("cli.website.snakesay") mock_echo = mocker.patch("cli.website.typer.echo")