Skip to content

Commit

Permalink
Reorganize cli imports
Browse files Browse the repository at this point in the history
The old way did not allow for having multiple commands of the same name
  • Loading branch information
ihabunek committed Dec 13, 2023
1 parent 72b4718 commit d11fa20
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 151 deletions.
2 changes: 1 addition & 1 deletion tests/integration/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


def test_env(run: Run):
result = run(cli.env)
result = run(cli.auth.env)
assert result.exit_code == 0
assert "toot" in result.stdout
assert "Python" in result.stdout
Expand Down
38 changes: 19 additions & 19 deletions tests/integration/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,83 @@


def test_lists_empty(run):
result = run(cli.lists)
result = run(cli.lists.lists)
assert result.exit_code == 0
assert result.stdout.strip() == "You have no lists defined."


def test_list_create_delete(run):
result = run(cli.list_create, "banana")
result = run(cli.lists.list_create, "banana")
assert result.exit_code == 0
assert result.stdout.strip() == '✓ List "banana" created.'

result = run(cli.lists)
result = run(cli.lists.lists)
assert result.exit_code == 0
assert "banana" in result.stdout

result = run(cli.list_create, "mango")
result = run(cli.lists.list_create, "mango")
assert result.exit_code == 0
assert result.stdout.strip() == '✓ List "mango" created.'

result = run(cli.lists)
result = run(cli.lists.lists)
assert result.exit_code == 0
assert "banana" in result.stdout
assert "mango" in result.stdout

result = run(cli.list_delete, "banana")
result = run(cli.lists.list_delete, "banana")
assert result.exit_code == 0
assert result.stdout.strip() == '✓ List "banana" deleted.'

result = run(cli.lists)
result = run(cli.lists.lists)
assert result.exit_code == 0
assert "banana" not in result.stdout
assert "mango" in result.stdout

result = run(cli.list_delete, "mango")
result = run(cli.lists.list_delete, "mango")
assert result.exit_code == 0
assert result.stdout.strip() == '✓ List "mango" deleted.'

result = run(cli.lists)
result = run(cli.lists.lists)
assert result.exit_code == 0
assert result.stdout.strip() == "You have no lists defined."

result = run(cli.list_delete, "mango")
result = run(cli.lists.list_delete, "mango")
assert result.exit_code == 1
assert result.stderr.strip() == "Error: List not found"


def test_list_add_remove(run, app):
acc = register_account(app)
run(cli.list_create, "foo")
run(cli.lists.list_create, "foo")

result = run(cli.list_add, "foo", acc.username)
result = run(cli.lists.list_add, "foo", acc.username)
assert result.exit_code == 1
assert result.stderr.strip() == f"Error: You must follow @{acc.username} before adding this account to a list."

run(cli.follow, acc.username)
run(cli.accounts.follow, acc.username)

result = run(cli.list_add, "foo", acc.username)
result = run(cli.lists.list_add, "foo", acc.username)
assert result.exit_code == 0
assert result.stdout.strip() == f'✓ Added account "{acc.username}"'

result = run(cli.list_accounts, "foo")
result = run(cli.lists.list_accounts, "foo")
assert result.exit_code == 0
assert acc.username in result.stdout

# Account doesn't exist
result = run(cli.list_add, "foo", "does_not_exist")
result = run(cli.lists.list_add, "foo", "does_not_exist")
assert result.exit_code == 1
assert result.stderr.strip() == "Error: Account not found"

# List doesn't exist
result = run(cli.list_add, "does_not_exist", acc.username)
result = run(cli.lists.list_add, "does_not_exist", acc.username)
assert result.exit_code == 1
assert result.stderr.strip() == "Error: List not found"

result = run(cli.list_remove, "foo", acc.username)
result = run(cli.lists.list_remove, "foo", acc.username)
assert result.exit_code == 0
assert result.stdout.strip() == f'✓ Removed account "{acc.username}"'

result = run(cli.list_accounts, "foo")
result = run(cli.lists.list_accounts, "foo")
assert result.exit_code == 0
assert result.stdout.strip() == "This list has no accounts."
44 changes: 22 additions & 22 deletions tests/integration/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def test_post(app, user, run):
text = "i wish i was a #lumberjack"
result = run(cli.post, text)
result = run(cli.post.post, text)
assert result.exit_code == 0

status_id = posted_status_id(result.stdout)
Expand All @@ -31,14 +31,14 @@ def test_post(app, user, run):


def test_post_no_text(run):
result = run(cli.post)
result = run(cli.post.post)
assert result.exit_code == 1
assert result.stderr.strip() == "Error: You must specify either text or media to post."


def test_post_json(run):
content = "i wish i was a #lumberjack"
result = run(cli.post, content, "--json")
result = run(cli.post.post, content, "--json")
assert result.exit_code == 0

status = json.loads(result.stdout)
Expand All @@ -51,7 +51,7 @@ def test_post_json(run):

def test_post_visibility(app, user, run):
for visibility in ["public", "unlisted", "private", "direct"]:
result = run(cli.post, "foo", "--visibility", visibility)
result = run(cli.post.post, "foo", "--visibility", visibility)
assert result.exit_code == 0

status_id = posted_status_id(result.stdout)
Expand All @@ -63,7 +63,7 @@ def test_post_scheduled_at(app, user, run):
text = str(uuid.uuid4())
scheduled_at = datetime.now(timezone.utc).replace(microsecond=0) + timedelta(minutes=10)

result = run(cli.post, text, "--scheduled-at", scheduled_at.isoformat())
result = run(cli.post.post, text, "--scheduled-at", scheduled_at.isoformat())
assert result.exit_code == 0

assert "Toot scheduled for" in result.stdout
Expand All @@ -74,7 +74,7 @@ def test_post_scheduled_at(app, user, run):


def test_post_scheduled_at_error(run):
result = run(cli.post, "foo", "--scheduled-at", "banana")
result = run(cli.post.post, "foo", "--scheduled-at", "banana")
assert result.exit_code == 1
# Stupid error returned by mastodon
assert result.stderr.strip() == "Error: Record invalid"
Expand All @@ -96,7 +96,7 @@ def test_post_scheduled_in(app, user, run):

datetimes = []
for scheduled_in, delta in variants:
result = run(cli.post, text, "--scheduled-in", scheduled_in)
result = run(cli.post.post, text, "--scheduled-in", scheduled_in)
assert result.exit_code == 0

dttm = datetime.utcnow() + delta
Expand All @@ -115,13 +115,13 @@ def test_post_scheduled_in(app, user, run):


def test_post_scheduled_in_invalid_duration(run):
result = run(cli.post, "foo", "--scheduled-in", "banana")
result = run(cli.post.post, "foo", "--scheduled-in", "banana")
assert result.exit_code == 2
assert "Invalid duration: banana" in result.stderr


def test_post_scheduled_in_empty_duration(run):
result = run(cli.post, "foo", "--scheduled-in", "0m")
result = run(cli.post.post, "foo", "--scheduled-in", "0m")
assert result.exit_code == 2
assert "Empty duration" in result.stderr

Expand All @@ -130,7 +130,7 @@ def test_post_poll(app, user, run):
text = str(uuid.uuid4())

result = run(
cli.post, text,
cli.post.post, text,
"--poll-option", "foo",
"--poll-option", "bar",
"--poll-option", "baz",
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_post_poll_multiple(app, user, run):
text = str(uuid.uuid4())

result = run(
cli.post, text,
cli.post.post, text,
"--poll-option", "foo",
"--poll-option", "bar",
"--poll-multiple"
Expand All @@ -177,7 +177,7 @@ def test_post_poll_expires_in(app, user, run):
text = str(uuid.uuid4())

result = run(
cli.post, text,
cli.post.post, text,
"--poll-option", "foo",
"--poll-option", "bar",
"--poll-expires-in", "8h",
Expand All @@ -197,7 +197,7 @@ def test_post_poll_hide_totals(app, user, run):
text = str(uuid.uuid4())

result = run(
cli.post, text,
cli.post.post, text,
"--poll-option", "foo",
"--poll-option", "bar",
"--poll-hide-totals"
Expand All @@ -216,14 +216,14 @@ def test_post_poll_hide_totals(app, user, run):


def test_post_language(app, user, run):
result = run(cli.post, "test", "--language", "hr")
result = run(cli.post.post, "test", "--language", "hr")
assert result.exit_code == 0

status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
assert status["language"] == "hr"

result = run(cli.post, "test", "--language", "zh")
result = run(cli.post.post, "test", "--language", "zh")
assert result.exit_code == 0

status_id = posted_status_id(result.stdout)
Expand All @@ -232,7 +232,7 @@ def test_post_language(app, user, run):


def test_post_language_error(run):
result = run(cli.post, "test", "--language", "banana")
result = run(cli.post.post, "test", "--language", "banana")
assert result.exit_code == 2
assert "Language should be a two letter abbreviation." in result.stderr

Expand All @@ -242,7 +242,7 @@ def test_media_thumbnail(app, user, run):
thumbnail_path = path.join(ASSETS_DIR, "test1.png")

result = run(
cli.post,
cli.post.post,
"--media", video_path,
"--thumbnail", thumbnail_path,
"--description", "foo",
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_media_attachments(app, user, run):
path4 = path.join(ASSETS_DIR, "test4.png")

result = run(
cli.post,
cli.post.post,
"--media", path1,
"--media", path2,
"--media", path3,
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_media_attachments(app, user, run):

def test_too_many_media(run):
m = path.join(ASSETS_DIR, "test1.png")
result = run(cli.post, "-m", m, "-m", m, "-m", m, "-m", m, "-m", m)
result = run(cli.post.post, "-m", m, "-m", m, "-m", m, "-m", m, "-m", m)
assert result.exit_code == 1
assert result.stderr.strip() == "Error: Cannot attach more than 4 files."

Expand All @@ -323,7 +323,7 @@ def test_media_attachment_without_text(mock_read, mock_ml, app, user, run):

media_path = path.join(ASSETS_DIR, "test1.png")

result = run(cli.post, "--media", media_path)
result = run(cli.post.post, "--media", media_path)
assert result.exit_code == 0

status_id = posted_status_id(result.stdout)
Expand All @@ -342,15 +342,15 @@ def test_media_attachment_without_text(mock_read, mock_ml, app, user, run):
def test_reply_thread(app, user, friend, run):
status = api.post_status(app, friend, "This is the status").json()

result = run(cli.post, "--reply-to", status["id"], "This is the reply")
result = run(cli.post.post, "--reply-to", status["id"], "This is the reply")
assert result.exit_code == 0

status_id = posted_status_id(result.stdout)
reply = api.fetch_status(app, user, status_id).json()

assert reply["in_reply_to_id"] == status["id"]

result = run(cli.thread, status["id"])
result = run(cli.read.thread, status["id"])
assert result.exit_code == 0

[s1, s2] = [s.strip() for s in re.split(r"─+", result.stdout) if s.strip()]
Expand Down
Loading

0 comments on commit d11fa20

Please sign in to comment.