mirror of
https://github.com/ihabunek/toot.git
synced 2024-09-29 04:35:54 -04:00
Simplify integration tests by catching ConsoleError
This commit is contained in:
parent
e3394c1693
commit
5cb8967c84
@ -22,6 +22,8 @@ import uuid
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from toot import api, App, User
|
from toot import api, App, User
|
||||||
from toot.console import run_command
|
from toot.console import run_command
|
||||||
|
from toot.exceptions import ApiError, ConsoleError
|
||||||
|
from toot.output import print_out
|
||||||
|
|
||||||
# Host name of a test instance to run integration tests against
|
# Host name of a test instance to run integration tests against
|
||||||
# DO NOT USE PUBLIC INSTANCES!!!
|
# DO NOT USE PUBLIC INSTANCES!!!
|
||||||
@ -84,7 +86,13 @@ def friend(app):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def run(app, user, capsys):
|
def run(app, user, capsys):
|
||||||
def _run(command, *params, as_user=None):
|
def _run(command, *params, as_user=None):
|
||||||
run_command(app, as_user or user, command, params or [])
|
# The try/catch duplicates logic from console.main to convert exceptions
|
||||||
|
# to printed error messages. TODO: could be deduped
|
||||||
|
try:
|
||||||
|
run_command(app, as_user or user, command, params or [])
|
||||||
|
except (ConsoleError, ApiError) as e:
|
||||||
|
print_out(str(e))
|
||||||
|
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert err == ""
|
assert err == ""
|
||||||
return strip_ansi(out)
|
return strip_ansi(out)
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
from tests.integration.conftest import TRUMPET
|
from tests.integration.conftest import TRUMPET
|
||||||
from toot import api
|
from toot import api
|
||||||
from toot.exceptions import ConsoleError
|
|
||||||
from toot.utils import get_text
|
from toot.utils import get_text
|
||||||
|
|
||||||
|
|
||||||
def test_update_account_no_options(run):
|
def test_update_account_no_options(run):
|
||||||
with pytest.raises(ConsoleError) as exc:
|
out = run("update_account")
|
||||||
run("update_account")
|
assert out == "Please specify at least one option to update the account"
|
||||||
assert str(exc.value) == "Please specify at least one option to update the account"
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_account_display_name(run, app, user):
|
def test_update_account_display_name(run, app, user):
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
|
|
||||||
import pytest
|
|
||||||
from tests.integration.conftest import register_account
|
from tests.integration.conftest import register_account
|
||||||
from toot.exceptions import ConsoleError
|
|
||||||
|
|
||||||
|
|
||||||
def test_lists_empty(run):
|
def test_lists_empty(run):
|
||||||
@ -36,9 +33,8 @@ def test_list_create_delete(run):
|
|||||||
out = run("lists")
|
out = run("lists")
|
||||||
assert out == "You have no lists defined."
|
assert out == "You have no lists defined."
|
||||||
|
|
||||||
with pytest.raises(ConsoleError) as exc:
|
out = run("list_delete", "mango")
|
||||||
run("list_delete", "mango")
|
assert out == "List not found"
|
||||||
assert str(exc.value) == "List not found"
|
|
||||||
|
|
||||||
|
|
||||||
def test_list_add_remove(run, app):
|
def test_list_add_remove(run, app):
|
||||||
@ -57,14 +53,12 @@ def test_list_add_remove(run, app):
|
|||||||
assert acc.username in out
|
assert acc.username in out
|
||||||
|
|
||||||
# Account doesn't exist
|
# Account doesn't exist
|
||||||
with pytest.raises(ConsoleError) as exc:
|
out = run("list_add", "foo", "does_not_exist")
|
||||||
run("list_add", "foo", "does_not_exist")
|
assert out == "Account not found"
|
||||||
assert str(exc.value) == "Account not found"
|
|
||||||
|
|
||||||
# List doesn't exist
|
# List doesn't exist
|
||||||
with pytest.raises(ConsoleError) as exc:
|
out = run("list_add", "does_not_exist", acc.username)
|
||||||
run("list_add", "does_not_exist", acc.username)
|
assert out == "List not found"
|
||||||
assert str(exc.value) == "List not found"
|
|
||||||
|
|
||||||
out = run("list_remove", "foo", acc.username)
|
out = run("list_remove", "foo", acc.username)
|
||||||
assert out == f'✓ Removed account "{acc.username}"'
|
assert out == f'✓ Removed account "{acc.username}"'
|
||||||
|
Loading…
Reference in New Issue
Block a user