From 9abba68f0b1e8203c19b5592555b9999bb20f959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 2 Jan 2020 15:22:39 +0100 Subject: [PATCH] :white_check_mark: Add tests for printing and terminating --- .../test_terminating/__init__.py | 0 .../test_terminating/test_tutorial001.py | 35 +++++++++++++++++++ .../test_terminating/test_tutorial002.py | 33 +++++++++++++++++ .../test_terminating/test_tutorial003.py | 34 ++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 tests/test_tutorial/test_terminating/__init__.py create mode 100644 tests/test_tutorial/test_terminating/test_tutorial001.py create mode 100644 tests/test_tutorial/test_terminating/test_tutorial002.py create mode 100644 tests/test_tutorial/test_terminating/test_tutorial003.py diff --git a/tests/test_tutorial/test_terminating/__init__.py b/tests/test_tutorial/test_terminating/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_tutorial/test_terminating/test_tutorial001.py b/tests/test_tutorial/test_terminating/test_tutorial001.py new file mode 100644 index 0000000..bfc7e6a --- /dev/null +++ b/tests/test_tutorial/test_terminating/test_tutorial001.py @@ -0,0 +1,35 @@ +import subprocess + +import typer +from typer.testing import CliRunner + +from terminating import tutorial001 as mod + +runner = CliRunner() + +app = typer.Typer() +app.command()(mod.main) + + +def test_cli(): + result = runner.invoke(app, ["Camila"]) + assert result.exit_code == 0 + assert "User created: Camila" in result.output + assert "Notification sent for new user: Camila" in result.output + + +def test_existing(): + result = runner.invoke(app, ["rick"]) + assert result.exit_code == 0 + assert "The user already exists" in result.output + assert "Notification sent for new user" not in result.output + + +def test_script(): + result = subprocess.run( + ["coverage", "run", mod.__file__, "--help"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + ) + assert "Usage" in result.stdout diff --git a/tests/test_tutorial/test_terminating/test_tutorial002.py b/tests/test_tutorial/test_terminating/test_tutorial002.py new file mode 100644 index 0000000..b12244b --- /dev/null +++ b/tests/test_tutorial/test_terminating/test_tutorial002.py @@ -0,0 +1,33 @@ +import subprocess + +import typer +from typer.testing import CliRunner + +from terminating import tutorial002 as mod + +runner = CliRunner() + +app = typer.Typer() +app.command()(mod.main) + + +def test_cli(): + result = runner.invoke(app, ["Camila"]) + assert result.exit_code == 0 + assert "New user created: Camila" in result.output + + +def test_root(): + result = runner.invoke(app, ["root"]) + assert result.exit_code == 1 + assert "The root user is reserved" in result.output + + +def test_script(): + result = subprocess.run( + ["coverage", "run", mod.__file__, "--help"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + ) + assert "Usage" in result.stdout diff --git a/tests/test_tutorial/test_terminating/test_tutorial003.py b/tests/test_tutorial/test_terminating/test_tutorial003.py new file mode 100644 index 0000000..a19a614 --- /dev/null +++ b/tests/test_tutorial/test_terminating/test_tutorial003.py @@ -0,0 +1,34 @@ +import subprocess + +import typer +from typer.testing import CliRunner + +from terminating import tutorial003 as mod + +runner = CliRunner() + +app = typer.Typer() +app.command()(mod.main) + + +def test_cli(): + result = runner.invoke(app, ["Camila"]) + assert result.exit_code == 0 + assert "New user created: Camila" in result.output + + +def test_root(): + result = runner.invoke(app, ["root"]) + assert result.exit_code == 1 + assert "The root user is reserved" in result.output + assert "Aborted!" in result.output + + +def test_script(): + result = subprocess.run( + ["coverage", "run", mod.__file__, "--help"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + ) + assert "Usage" in result.stdout