Skip to content

Commit

Permalink
Fix for missing logfiles.
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 9a9b81f commit 5f1188e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
27 changes: 16 additions & 11 deletions cli/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,22 @@ def get(
website = Website()
if domain_name is not None:
website_info = website.get(domain_name=domain_name)
table = tabulate(
[
["domain name", website_info["domain_name"]],
["enabled", website_info["enabled"]],
["command", website_info["webapp"]["command"]],
["access log", website_info["logfiles"]["access"]],
["error log", website_info["logfiles"]["error"]],
["server log", website_info["logfiles"]["server"]],
],
tablefmt="simple",
)
tabular_data = [
["domain name", website_info["domain_name"]],
["enabled", website_info["enabled"]],
["command", website_info["webapp"]["command"]],

]
if "logfiles" in website_info:
tabular_data.extend(
[
["access log", website_info["logfiles"]["access"]],
["error log", website_info["logfiles"]["error"]],
["server log", website_info["logfiles"]["server"]],
]
)

table = tabulate(tabular_data, tablefmt="simple")
else:
websites = website.list()
table = tabulate(
Expand Down
46 changes: 46 additions & 0 deletions tests/test_cli_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,52 @@ def test_get_with_domain_gives_details_for_domain(mocker, website_info, domain_n
mock_echo.assert_called_once_with(mock_tabulate.return_value)


def test_get_with_domain_gives_details_for_domain_even_without_logfiles(
mocker, domain_name, command
):
website_info = {
"domain_name": domain_name,
"enabled": True,
"id": 42,
"user": getpass.getuser(),
"webapp": {
"command": command,
"domains": [
{
"domain_name": domain_name,
"enabled": True
}
],
"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")

result = runner.invoke(
app,
[
"get",
"-d",
domain_name
],
)

assert result.exit_code == 0
mock_website.return_value.get.assert_called_once_with(domain_name=domain_name)
assert mock_tabulate.call_args == call(
[
["domain name", website_info["domain_name"]],
["enabled", website_info["enabled"]],
["command", website_info["webapp"]["command"]],
],
tablefmt="simple",
)
mock_echo.assert_called_once_with(mock_tabulate.return_value)


def test_reload_with_no_domain_barfs():
result = runner.invoke(
app,
Expand Down

0 comments on commit 5f1188e

Please sign in to comment.