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

User status key error #615

Closed
wants to merge 3 commits into from
Closed
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
33 changes: 33 additions & 0 deletions tests/test_sign_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
from unittest import mock

from requests import Response

from user_sync.post_sync.connectors.sign_sync.client import SignClient


@mock.patch('requests.get')
@mock.patch('user_sync.post_sync.connectors.sign_sync.client.SignClient._init')
def test_get_users(mock_client, mock_get):
def mock_response(data):
r = Response()
r.status_code = 200
r._content = json.dumps(data).encode()
return r
config = {
'console_org': None,
'host': 'example.com',
'key': '1234567890',
'admin_email': '[email protected]'
}
user_list = mock_response({'userInfoList': [{"userId": "active"}, {"userId": "inactive"}, {"userId": "nostatus"}]})
active_user = mock_response({'userStatus': 'ACTIVE', 'email': '[email protected]'})
inactive_user = mock_response({'userStatus': 'INACTIVE', 'email': '[email protected]'})
no_status_user = mock_response({'email': '[email protected]'})

mock_get.side_effect = [user_list, active_user, inactive_user, no_status_user]
sc = SignClient(config)
sc.api_url = "example.com"
users = sc.get_users()
assert '[email protected]' and '[email protected]' in users
assert '[email protected]' not in users
5 changes: 2 additions & 3 deletions user_sync/post_sync/connectors/sign_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,18 @@ def get_users(self):
"""
if self.api_url is None or self.groups is None:
self._init()

users = {}
self.logger.debug('getting list of all Sign users')
users_res = requests.get(self.api_url + 'users', headers=self.header())

if users_res.status_code != 200:
raise AssertionException("Error retrieving Sign user list")
for user_id in map(lambda u: u['userId'], users_res.json()['userInfoList']):
user_res = requests.get(self.api_url + 'users/' + user_id, headers=self.header())
if users_res.status_code != 200:
raise AssertionException("Error retrieving details for Sign user '{}'".format(user_id))
user = user_res.json()
if user['userStatus'] != 'ACTIVE':
user_status = user.get('userStatus')
if user_status and user_status != 'ACTIVE':
continue
if user['email'] == self.admin_email:
continue
Expand Down