From 54fcb2316483d159a800964a4f08def420120810 Mon Sep 17 00:00:00 2001 From: Filip Lajszczak Date: Fri, 20 Nov 2020 13:34:46 +0000 Subject: [PATCH] #5 despiking of webapp reload --- cli/webapp.py | 7 ++++++- tests/test_cli_webapp.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/test_cli_webapp.py diff --git a/cli/webapp.py b/cli/webapp.py index 10e8fe3..0f34a2a 100644 --- a/cli/webapp.py +++ b/cli/webapp.py @@ -11,7 +11,12 @@ @app.command() def reload( - domain_name: str = typer.Option("your-username.pythonanywhere.com", help="Domain name") + domain_name: str = typer.Option( + "your-username.pythonanywhere.com", + "-d", + "--domain", + help="Domain name, eg www.mydomain.com [default: your-username.pythonanywhere.com]", + ) ): domain_name = ensure_domain(domain_name) webapp = Webapp(domain_name) diff --git a/tests/test_cli_webapp.py b/tests/test_cli_webapp.py new file mode 100644 index 0000000..1ecfae6 --- /dev/null +++ b/tests/test_cli_webapp.py @@ -0,0 +1,19 @@ +from unittest.mock import Mock, call + +from typer.testing import CliRunner + +from cli.webapp import app + +runner = CliRunner() + + +def test_reload(mocker): + mock_webapp = mocker.patch("cli.webapp.Webapp") + mocker.patch("cli.webapp.ensure_domain", Mock(side_effect=lambda x: x)) + domain_name = "foo.bar.baz" + + result = runner.invoke(app, ["reload", "-d", domain_name]) + + assert f"{domain_name} has been reloaded" in result.stdout + mock_webapp.assert_called_once_with(domain_name) + assert mock_webapp.return_value.method_calls == [call.reload()]