Skip to content

Commit

Permalink
Merge branch 'PA-596'
Browse files Browse the repository at this point in the history
  • Loading branch information
filiplajszczak committed Oct 22, 2024
2 parents 46f7524 + c9179a6 commit 2268d2f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cli/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing_extensions import Annotated

import json
import typer
from snakesay import snakesay
from tabulate import tabulate
Expand Down Expand Up @@ -57,9 +56,9 @@ def get(
website_info = website.get(domain_name=domain_name)
tabular_data = [
["domain name", website_info["domain_name"]],
["cname", website_info["webapp"]["domains"][0].get("cname")],
["enabled", website_info["enabled"]],
["command", website_info["webapp"]["command"]],

]
if "logfiles" in website_info:
tabular_data.extend(
Expand All @@ -69,6 +68,7 @@ def get(
["server log", website_info["logfiles"]["server"]],
]
)
tabular_data = [[k, v] for k, v in tabular_data if v is not None]

table = tabulate(tabular_data, tablefmt="simple")
else:
Expand Down
88 changes: 88 additions & 0 deletions tests/test_cli_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,94 @@ def test_get_with_domain_gives_details_for_domain_even_without_logfiles(
mock_echo.assert_called_once_with(mock_tabulate.return_value)


def test_get_includes_cname_if_cname_is_present_in_domain(
domain_name, command, mock_echo, mock_tabulate, mock_website
):
website_info = {
"domain_name": domain_name,
"enabled": True,
"id": 42,
"user": getpass.getuser(),
"webapp": {
"command": command,
"domains": [
{
"domain_name": domain_name,
"enabled": True,
"cname": "the-cname"
}
],
"id": 42
}
}
mock_website.return_value.get.return_value = website_info

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"]],
["cname", website_info["webapp"]["domains"][0]["cname"]],
["enabled", website_info["enabled"]],
["command", website_info["webapp"]["command"]],
],
tablefmt="simple",
)
mock_echo.assert_called_once_with(mock_tabulate.return_value)


def test_get_does_not_include_cname_if_cname_is_not_present_in_domain(
domain_name, command, mock_echo, mock_tabulate, mock_website
):
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.return_value.get.return_value = website_info

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 2268d2f

Please sign in to comment.