Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for listing active users #258

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dmapiclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '23.0.0'
__version__ = '23.1.0'

from .errors import APIError, HTTPError, InvalidResponse # noqa
from .errors import REQUEST_ERROR_STATUS_CODE, REQUEST_ERROR_MESSAGE # noqa
Expand Down
3 changes: 3 additions & 0 deletions dmapiclient/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def find_users(
personal_data_removed=None,
*,
user_research_opted_in=None,
active=None,
):
warnings.warn(
"The output of 'find_users' is paginated. Use 'find_users_iter' instead.",
Expand All @@ -410,6 +411,8 @@ def find_users(
params['personal_data_removed'] = personal_data_removed
if user_research_opted_in is not None:
params['user_research_opted_in'] = user_research_opted_in
if active is not None:
params['active'] = active
return self._get("/users", params=params)

find_users_iter = make_iter_method('find_users', 'users')
Expand Down
24 changes: 23 additions & 1 deletion tests/test_data_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def user():
'email_address': 'email_address',
'name': 'name',
'role': 'supplier',
'active': 'active',
'active': True,
'locked': False,
'created_at': "2015-05-05T05:05:05",
'updated_at': "2015-05-05T05:05:05",
Expand Down Expand Up @@ -297,6 +297,28 @@ def test_find_users_by_user_research_opted_in_true(self, data_client, rmock):

assert user == expected_data

def test_find_users_by_active_false(self, data_client, rmock):
rmock.get(
"http://baseurl/users?active=false",
json=self.user(),
status_code=200)
user = data_client.find_users(active=False)

assert user == self.user()

def test_find_users_by_active_true(self, data_client, rmock):
user = self.user()
user['users'].update({'active': True})
expected_data = user.copy()

rmock.get(
"http://baseurl/users?active=true",
json=user,
status_code=200)
user = data_client.find_users(active=True)

assert user == expected_data

def test_get_user_by_id(self, data_client, rmock):
rmock.get(
"http://baseurl/users/1234",
Expand Down