-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
85 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Controller classes for :py:class:`.iNatClient`.""" | ||
"""Controller classes for :py:class:`.iNatClient`""" | ||
# flake8: noqa: F401 | ||
from pyinaturalist.controllers.base import BaseController | ||
from pyinaturalist.controllers.observations import ObservationController | ||
from pyinaturalist.controllers.projects import ProjectController | ||
from pyinaturalist.controllers.taxa import TaxonController | ||
from pyinaturalist.controllers.users import UserController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Iterator, List | ||
from pyinaturalist.controllers import BaseController | ||
from pyinaturalist.docs import document_controller_params | ||
from pyinaturalist.models import User | ||
|
||
from pyinaturalist.v1 import get_user_by_id, get_users_autocomplete | ||
|
||
|
||
class UserController(BaseController): | ||
""":fa:`user` Controller for User requests""" | ||
|
||
# TODO: Paginator subclass for this? | ||
def from_id(self, *user_ids, **params) -> Iterator[User]: | ||
"""Get users by ID | ||
Args: | ||
user_ids: One or more project IDs | ||
""" | ||
for user_id in user_ids: | ||
response = get_user_by_id(user_id, **params) | ||
yield User.from_json(response) | ||
|
||
@document_controller_params(get_users_autocomplete) | ||
def autocomplete(self, **params) -> List[User]: | ||
response = get_users_autocomplete(**params) | ||
return User.from_json_list(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pyinaturalist.client import iNatClient | ||
from pyinaturalist.constants import API_V1_BASE_URL | ||
from pyinaturalist.models import User | ||
from test.sample_data import SAMPLE_DATA | ||
|
||
|
||
def test_from_id(requests_mock): | ||
user_id = 1 | ||
requests_mock.get( | ||
f'{API_V1_BASE_URL}/users/{user_id}', | ||
json=SAMPLE_DATA['get_user_by_id'], | ||
status_code=200, | ||
) | ||
|
||
client = iNatClient() | ||
results = list(client.users.from_id(user_id)) | ||
assert len(results) == 1 and isinstance(results[0], User) | ||
assert results[0].id == user_id | ||
|
||
|
||
def test_autocomplete(requests_mock): | ||
requests_mock.get( | ||
f'{API_V1_BASE_URL}/users/autocomplete', | ||
json=SAMPLE_DATA['get_users_autocomplete'], | ||
status_code=200, | ||
) | ||
|
||
client = iNatClient() | ||
results = client.users.autocomplete(q='nico') | ||
assert len(results) == 3 and isinstance(results[0], User) | ||
assert results[0].id == 886482 |