Introduction
Introduction Statistics Contact Development Disclaimer Help
Search only accounts when looking for users - toot - Unnamed repository; edit t…
Log
Files
Refs
LICENSE
---
commit 6766cf83b4fcd2af297906de4213b9dc5923049d
parent 02e364b52196c5391e20e08dc2fb9de227fa3bed
Author: Ivan Habunek <[email protected]>
Date: Sun, 7 May 2017 10:42:04 +0200
Search only accounts when looking for users
Instead of using general search.
Diffstat:
tests/test_console.py | 44 +++++++++++++------------------
toot/commands.py | 17 +++++++++++++----
2 files changed, 31 insertions(+), 30 deletions(-)
---
diff --git a/tests/test_console.py b/tests/test_console.py
@@ -179,16 +179,14 @@ def test_search(monkeypatch, capsys):
def test_follow(monkeypatch, capsys):
def mock_get(url, params, headers):
- assert url == 'https://habunek.com/api/v1/search'
- assert params == {'q': 'blixa', 'resolve': False}
+ assert url == 'https://habunek.com/api/v1/accounts/search'
+ assert params == {'q': 'blixa'}
assert headers == {'Authorization': 'Bearer xxx'}
- return MockResponse({
- 'accounts': [
- {'id': 123, 'acct': '[email protected]'},
- {'id': 321, 'acct': 'blixa'},
- ]
- })
+ return MockResponse([
+ {'id': 123, 'acct': '[email protected]'},
+ {'id': 321, 'acct': 'blixa'},
+ ])
def mock_prepare(request):
assert request.url == 'https://habunek.com/api/v1/accounts/321/follow'
@@ -208,13 +206,11 @@ def test_follow(monkeypatch, capsys):
def test_follow_not_found(monkeypatch, capsys):
def mock_get(url, params, headers):
- assert url == 'https://habunek.com/api/v1/search'
- assert params == {'q': 'blixa', 'resolve': False}
+ assert url == 'https://habunek.com/api/v1/accounts/search'
+ assert params == {'q': 'blixa'}
assert headers == {'Authorization': 'Bearer xxx'}
- return MockResponse({
- 'accounts': []
- })
+ return MockResponse([])
monkeypatch.setattr(requests, 'get', mock_get)
@@ -225,16 +221,14 @@ def test_follow_not_found(monkeypatch, capsys):
def test_unfollow(monkeypatch, capsys):
def mock_get(url, params, headers):
- assert url == 'https://habunek.com/api/v1/search'
- assert params == {'q': 'blixa', 'resolve': False}
+ assert url == 'https://habunek.com/api/v1/accounts/search'
+ assert params == {'q': 'blixa'}
assert headers == {'Authorization': 'Bearer xxx'}
- return MockResponse({
- 'accounts': [
- {'id': 123, 'acct': '[email protected]'},
- {'id': 321, 'acct': 'blixa'},
- ]
- })
+ return MockResponse([
+ {'id': 123, 'acct': '[email protected]'},
+ {'id': 321, 'acct': 'blixa'},
+ ])
def mock_prepare(request):
assert request.url == 'https://habunek.com/api/v1/accounts/321/unfollo…
@@ -254,13 +248,11 @@ def test_unfollow(monkeypatch, capsys):
def test_unfollow_not_found(monkeypatch, capsys):
def mock_get(url, params, headers):
- assert url == 'https://habunek.com/api/v1/search'
- assert params == {'q': 'blixa', 'resolve': False}
+ assert url == 'https://habunek.com/api/v1/accounts/search'
+ assert params == {'q': 'blixa'}
assert headers == {'Authorization': 'Bearer xxx'}
- return MockResponse({
- 'accounts': []
- })
+ return MockResponse([])
monkeypatch.setattr(requests, 'get', mock_get)
diff --git a/toot/commands.py b/toot/commands.py
@@ -266,11 +266,20 @@ def _do_upload(app, user, file):
def _find_account(app, user, account_name):
- """For a given account name, returns the Account object or raises an excep…
- response = api.search(app, user, account_name, False)
+ """For a given account name, returns the Account object.
- for account in response['accounts']:
- if account['acct'] == account_name or "@" + account['acct'] == account…
+ Raises an exception if not found.
+ """
+ if not account_name:
+ raise ConsoleError("Empty account name given")
+
+ accounts = api.search_accounts(app, user, account_name)
+
+ if account_name[0] == "@":
+ account_name = account_name[1:]
+
+ for account in accounts:
+ if account['acct'] == account_name:
return account
raise ConsoleError("Account not found")
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.