Skip to content

Commit

Permalink
PA-655 dummy command for creating new-style websites. by: Piotr, Giles
Browse files Browse the repository at this point in the history
  • Loading branch information
gpjt committed Jul 3, 2024
1 parent 38e7bc8 commit 552bbaa
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 11 deletions.
36 changes: 31 additions & 5 deletions cli/pa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,44 @@
from cli import schedule
from cli import students
from cli import webapp
from cli import website

help = """This is a new experimental PythonAnywhere cli client.
It was build with typer & click under the hood.
"""

app = typer.Typer(help=help, no_args_is_help=True, context_settings={"help_option_names": ["--help", "-h"]})
app.add_typer(django.app, name="django", help="Makes Django Girls tutorial projects deployment easy")
app.add_typer(path.app, name="path", help="Perform some operations on files")
app.add_typer(schedule.app, name="schedule", help="Manage scheduled tasks")
app.add_typer(students.app, name="students", help="Perform some operations on students")
app.add_typer(webapp.app, name="webapp", help="Everything for web apps")
app.add_typer(
django.app,
name="django",
help="Makes Django Girls tutorial projects deployment easy"
)
app.add_typer(
path.app,
name="path",
help="Perform some operations on files"
)
app.add_typer(
schedule.app,
name="schedule",
help="Manage scheduled tasks"
)
app.add_typer(
students.app,
name="students",
help="Perform some operations on students"
)
app.add_typer(
webapp.app,
name="webapp",
help="Everything for web apps: use this if you're not using our experimental features"
)
app.add_typer(
website.app,
name="website",
help="EXPERIMENTAL: create and manage ASGI websites"
)


if __name__ == "__main__":
Expand Down
33 changes: 33 additions & 0 deletions cli/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python3
import typer
from typing_extensions import Annotated


app = typer.Typer(no_args_is_help=True)

@app.command()
def create(
domain_name: Annotated[
str,
typer.Option(
"-d",
"--domain",
help="Domain name, eg. yourusername.pythonanywhere.com or www.mydomain.com",
)
],
command: Annotated[
str,
typer.Option(
"-c",
"--command",
help="The command to start up your server",
)
],
):
"""Create an ASGI website"""
pass


@app.command()
def delete():
pass
14 changes: 8 additions & 6 deletions tests/test_cli_pa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def test_main_command_without_args_prints_help():
[],
)
assert result.exit_code == 0
assert "This is a new experimental PythonAnywhere cli client." in result.stdout
assert "Makes Django Girls tutorial projects deployment easy" in result.stdout
assert "Perform some operations on files" in result.stdout
assert "Manage scheduled tasks" in result.stdout
assert "Perform some operations on students" in result.stdout
assert "Everything for web apps" in result.stdout
tidied_output = " ".join([line.replace("│", "").strip() for line in result.stdout.split("\n")])
assert "This is a new experimental PythonAnywhere cli client." in tidied_output
assert "Makes Django Girls tutorial projects deployment easy" in tidied_output
assert "Perform some operations on files" in tidied_output
assert "Manage scheduled tasks" in tidied_output
assert "Perform some operations on students" in tidied_output
assert "Everything for web apps: use this if you're not using our experimental features" in tidied_output
assert "EXPERIMENTAL: create and manage ASGI websites" in tidied_output


56 changes: 56 additions & 0 deletions tests/test_cli_website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from typer.testing import CliRunner

from cli.website import app

runner = CliRunner()


def test_main_subcommand_without_args_prints_help():
result = runner.invoke(
app,
[],
)
assert result.exit_code == 0
assert "Show this message and exit." in result.stdout


def test_create_without_domain_barfs():
result = runner.invoke(
app,
[
"create",
"-c",
"some kind of server",
],
)
assert result.exit_code != 0
assert "Missing option" in result.stdout


def test_create_without_command_barfs():
result = runner.invoke(
app,
[
"create",
"-d",
"www.something.com",
],
)
assert result.exit_code != 0
assert "Missing option" in result.stdout


def test_create_with_domain_and_command_does_something():
result = runner.invoke(
app,
[
"create",
"-d",
"www.something.com",
"-c",
"some kind of server",
],
)
assert result.exit_code == 0


0 comments on commit 552bbaa

Please sign in to comment.