1
0
mirror of https://github.com/ihabunek/toot synced 2024-12-23 15:37:47 +01:00

Remove duplicate search api fn

This commit is contained in:
Ivan Habunek 2022-11-27 09:56:58 +01:00
parent ebc17e0764
commit 7b194880a0
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
3 changed files with 14 additions and 19 deletions

View File

@ -350,6 +350,7 @@ def test_search(mock_get, capsys):
mock_get.assert_called_once_with(app, user, '/api/v2/search', {
'q': 'freddy',
'type': None,
'resolve': False,
})

View File

@ -278,21 +278,18 @@ def upload_media(app, user, file, description=None):
).json()
def search(app, user, query, resolve):
return http.get(app, user, '/api/v2/search', {
'q': query,
'resolve': resolve,
def search(app, user, query, resolve=False, type=None):
"""
Perform a search.
https://docs.joinmastodon.org/methods/search/#v2
"""
return http.get(app, user, "/api/v2/search", {
"q": query,
"resolve": resolve,
"type": type
}).json()
def search_accounts(app, user, query):
return http.get(app, user, '/api/v2/search', {
'q': query,
'type': 'accounts',
'resolve': True,
}).json()['accounts']
def follow(app, user, account):
return _account_action(app, user, account, 'follow')

View File

@ -255,14 +255,11 @@ def _find_account(app, user, account_name):
if not account_name:
raise ConsoleError("Empty account name given")
accounts = api.search_accounts(app, user, account_name)
normalized_name = account_name.lstrip("@").lower()
if account_name[0] == "@":
account_name = account_name[1:]
for account in accounts:
# Normalise string matching because usernames are case insensitive
if account['acct'].lower() == account_name.lower():
response = api.search(app, user, account_name, type="accounts", resolve=True)
for account in response["accounts"]:
if account["acct"].lower() == normalized_name:
return account
raise ConsoleError("Account not found")