diff --git a/tests/integration/test_read.py b/tests/integration/test_read.py index da18769..881a958 100644 --- a/tests/integration/test_read.py +++ b/tests/integration/test_read.py @@ -1,9 +1,10 @@ -import re -from uuid import uuid4 +import json import pytest +import re from toot import api from toot.exceptions import ConsoleError +from uuid import uuid4 def test_instance(app, run): @@ -13,6 +14,14 @@ def test_instance(app, run): assert "running Mastodon" in out +def test_instance_json(app, run): + out = run("instance", "--json") + data = json.loads(out) + assert data["title"] is not None + assert data["description"] is not None + assert data["version"] is not None + + def test_instance_anon(app, run_anon, base_url): out = run_anon("instance", base_url) assert "Mastodon" in out diff --git a/toot/auth.py b/toot/auth.py index 5ba301e..0311013 100644 --- a/toot/auth.py +++ b/toot/auth.py @@ -40,7 +40,7 @@ def create_app_interactive(base_url): def get_instance_domain(base_url): print_out("Looking up instance info...") - instance = api.get_instance(base_url) + instance = api.get_instance(base_url).json() print_out( f"Found instance {instance['title']} " diff --git a/toot/commands.py b/toot/commands.py index 0cdaaa6..503147f 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -542,15 +542,19 @@ def instance(app, user, args): raise ConsoleError("Please specify an instance.") try: - instance = api.get_instance(base_url).json() - instance = from_dict(Instance, instance) - print_instance(instance) + response = api.get_instance(base_url) except ApiError: raise ConsoleError( f"Instance not found at {base_url}.\n" "The given domain probably does not host a Mastodon instance." ) + if args.json: + print(response.text) + else: + instance = from_dict(Instance, response.json()) + print_instance(instance) + def notifications(app, user, args): if args.clear: diff --git a/toot/console.py b/toot/console.py index 9515d68..5638502 100644 --- a/toot/console.py +++ b/toot/console.py @@ -439,6 +439,7 @@ READ_COMMANDS = [ "nargs": "?", }), scheme_arg, + json_arg, ], require_auth=False, ), @@ -454,6 +455,7 @@ READ_COMMANDS = [ "default": False, "help": "Resolve non-local accounts", }), + json_arg, ], require_auth=True, ),