Skip to content

Commit f1422e7

Browse files
committed
Added TestCase for Bug issue #43 and Fixed create_test_user_uid() function
1 parent 9c62626 commit f1422e7

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

tests/connector/directory_okta_test.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import okta
2626
import json
2727
import tests.helper
28+
import copy
2829

2930
from user_sync.error import AssertionException
3031
from user_sync.connector.directory_okta import OktaDirectoryConnector, \
@@ -156,7 +157,7 @@ def tearDown(self):
156157
def test_found_user_single_group(self, mock_members):
157158
# There are 1 users in the Group. This test should return 1 users.
158159
groups = ['group1']
159-
test_user = tests.helper.create_test_user_uid(groups[0])
160+
test_user = tests.helper.create_test_user_uid()
160161
mock_members.return_value = [test_user]
161162
directory = self.directory
162163
results = directory.load_users_and_groups(groups, [])
@@ -168,7 +169,7 @@ def test_found_user_multiple_groups(self, mock_members):
168169
groups = ['group1', 'group2']
169170
test_users = []
170171
for group in groups:
171-
test_users.append([tests.helper.create_test_user_uid([group])])
172+
test_users.append([tests.helper.create_test_user_uid()])
172173
mock_members.side_effect = test_users
173174
directory = self.directory
174175
results = directory.load_users_and_groups(groups, [])
@@ -181,7 +182,7 @@ def test_found_user_single_group_multiple_user(self, mock_members):
181182
test_users = []
182183
user_count = 0
183184
while user_count < 5:
184-
test_users.append(tests.helper.create_test_user_uid(groups[0]))
185+
test_users.append(tests.helper.create_test_user_uid())
185186
user_count = user_count + 1
186187
mock_members.return_value = test_users
187188
directory = self.directory
@@ -197,7 +198,7 @@ def test_found_user_multiple_groups_multiple_user(self, mock_members):
197198
test_users = []
198199
user_count = 0
199200
while user_count < 5:
200-
test_users.append(tests.helper.create_test_user_uid(group))
201+
test_users.append(tests.helper.create_test_user_uid())
201202
user_count = user_count + 1
202203
total_test_users.append(test_users)
203204
mock_members.side_effect = total_test_users
@@ -225,7 +226,18 @@ def test_no_user_multiple_groups(self, mock_members):
225226
results = directory.load_users_and_groups(groups, [])
226227
self.assertEqual(len(list(results)), 0)
227228

228-
# Used to Test UserGroupsClient , iter_group_members Definations
229+
@mock.patch('user_sync.connector.directory_okta.OktaDirectoryConnector.iter_group_members')
230+
def test_same_user_in_multiple_groups(self, mock_members):
231+
# BUG User A suppose to be Group 1 and Group 2.
232+
groups = ['group1', 'group2']
233+
test_user = tests.helper.create_test_user_uid()
234+
mock_members.side_effect = [[test_user], [copy.deepcopy(test_user)]]
235+
directory = self.directory
236+
result = directory.load_users_and_groups(groups, [])
237+
result_list = list(result)
238+
self.assertEqual(result_list[0]['groups'], ['group1','group2'])
239+
240+
# Used to Test UserGroupsClient , iter_group_members Definitions
229241
class TestOktaIterGroupMember(unittest.TestCase):
230242
def setUp(self):
231243
class MockResponse:

tests/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def create_test_user(groups):
5151
}
5252
return user
5353

54-
def create_test_user_uid(groups):
54+
def create_test_user_uid():
5555
global next_user_id
5656
firstName = 'User_%d' % next_user_id
5757
uid = '0000%s' % next_user_id
@@ -63,7 +63,7 @@ def create_test_user_uid(groups):
6363
'lastname': 'Test',
6464
'email': '%[email protected]' % firstName,
6565
'country': 'CA' if (next_user_id % 2 == 0) else 'US',
66-
'groups': groups
66+
'groups': []
6767
}
6868
return user
6969

0 commit comments

Comments
 (0)