From 68bf18213b47571861a875eb23ba5a2e67bddba3 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sat, 26 Nov 2022 18:45:20 +0100 Subject: [PATCH] Change api.create_app to take an url --- tests/test_api.py | 2 +- tests/test_integration.py | 5 +++-- toot/api.py | 4 ++-- toot/auth.py | 8 ++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index de3da73..eb8855f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -15,7 +15,7 @@ def test_create_app(mock_post): 'client_secret': 'bar', }) - create_app('bigfish.software') + create_app('https://bigfish.software') mock_post.assert_called_once_with('https://bigfish.software/api/v1/apps', json={ 'website': CLIENT_WEBSITE, diff --git a/tests/test_integration.py b/tests/test_integration.py index 68c609b..2ba0d84 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -43,8 +43,9 @@ if not HOSTNAME or not DATABASE_DSN: def create_app(): - response = api.create_app(HOSTNAME, scheme="http") - return App(HOSTNAME, f"http://{HOSTNAME}", response["client_id"], response["client_secret"]) + base_url = f"http://{HOSTNAME}" + response = api.create_app(base_url) + return App(HOSTNAME, base_url, response["client_id"], response["client_secret"]) def register_account(app: App): diff --git a/toot/api.py b/toot/api.py index 2bcb608..8574ea2 100644 --- a/toot/api.py +++ b/toot/api.py @@ -24,8 +24,8 @@ def _status_action(app, user, status_id, action): return http.post(app, user, url).json() -def create_app(domain, scheme='https'): - url = '{}://{}/api/v1/apps'.format(scheme, domain) +def create_app(base_url): + url = f"{base_url}/api/v1/apps" json = { 'client_name': CLIENT_NAME, diff --git a/toot/auth.py b/toot/auth.py index 1b4a327..63bb4f1 100644 --- a/toot/auth.py +++ b/toot/auth.py @@ -18,15 +18,15 @@ def register_app(domain, scheme='https'): print_out("Found instance {} running Mastodon version {}".format( instance['title'], instance['version'])) + base_url = f"{scheme}://{domain}" + try: print_out("Registering application...") - response = api.create_app(domain, scheme) + response = api.create_app(base_url) except ApiError: raise ConsoleError("Registration failed.") - base_url = scheme + '://' + domain - - app = App(domain, base_url, response['client_id'], response['client_secret']) + app = App(domain, base_url, response["client_id"], response["client_secret"]) config.save_app(app) print_out("Application tokens saved.")