Skip to content

Commit

Permalink
fixturize mock of website.
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Kaznowski <[email protected]>
  • Loading branch information
filiplajszczak and caseneuve committed Jul 11, 2024
1 parent 5f1188e commit 133754a
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions tests/test_cli_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
[
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 133754a

Please sign in to comment.