53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
import os
|
|
import tempfile
|
|
|
|
from typer.testing import CliRunner
|
|
|
|
from porchlight.cli import app
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
def test_create_invite_prints_registration_url() -> None:
|
|
"""create-invite should print a URL containing /register/."""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
db_path = os.path.join(tmpdir, "test.db")
|
|
result = runner.invoke(
|
|
app,
|
|
["testuser"],
|
|
env={"OIDC_OP_ISSUER": "https://example.com", "OIDC_OP_SQLITE_PATH": db_path},
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert "https://example.com/register/" in result.output
|
|
|
|
|
|
def test_create_invite_with_note() -> None:
|
|
"""create-invite with --note should work."""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
db_path = os.path.join(tmpdir, "test.db")
|
|
result = runner.invoke(
|
|
app,
|
|
["testuser", "--note", "Welcome aboard"],
|
|
env={"OIDC_OP_ISSUER": "https://example.com", "OIDC_OP_SQLITE_PATH": db_path},
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert "https://example.com/register/" in result.output
|
|
|
|
|
|
def test_create_invite_with_custom_ttl() -> None:
|
|
"""create-invite with --ttl should use the custom TTL."""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
db_path = os.path.join(tmpdir, "test.db")
|
|
result = runner.invoke(
|
|
app,
|
|
["testuser", "--ttl", "3600"],
|
|
env={"OIDC_OP_ISSUER": "https://example.com", "OIDC_OP_SQLITE_PATH": db_path},
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert "https://example.com/register/" in result.output
|
|
|
|
|
|
def test_create_invite_missing_username_shows_error() -> None:
|
|
"""create-invite without a username should show an error."""
|
|
result = runner.invoke(app, [])
|
|
assert result.exit_code != 0
|