Search only accounts when looking for users
Instead of using general search.
This commit is contained in:
parent
02e364b521
commit
6766cf83b4
2 changed files with 31 additions and 30 deletions
|
@ -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': 'blixa@other.acc'},
|
||||
{'id': 321, 'acct': 'blixa'},
|
||||
]
|
||||
})
|
||||
return MockResponse([
|
||||
{'id': 123, 'acct': 'blixa@other.acc'},
|
||||
{'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': 'blixa@other.acc'},
|
||||
{'id': 321, 'acct': 'blixa'},
|
||||
]
|
||||
})
|
||||
return MockResponse([
|
||||
{'id': 123, 'acct': 'blixa@other.acc'},
|
||||
{'id': 321, 'acct': 'blixa'},
|
||||
])
|
||||
|
||||
def mock_prepare(request):
|
||||
assert request.url == 'https://habunek.com/api/v1/accounts/321/unfollow'
|
||||
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 exception if not found."""
|
||||
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_name:
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue