def merge_all_users_for_person(person): destination_user = None users_to_merge = [] for user in get_all_users_for_person(person): if user.login_id == person.uwnetid: # Current login_id destination_user = user else: users_to_merge.append(user) if destination_user and len(users_to_merge): canvas = Users() for user in users_to_merge: canvas.merge_users(user, destination_user) logger.info('Merged user {} into {}'.format( user.user_id, destination_user.user_id)) return destination_user
def test_merge_users(self, mock_merge): canvas = Users() user = CanvasUser( user_id=12345, name="J AVG USR", login_id="testid99", sis_user_id="DEB35E0A465242CF9C5CDBC108050EC0", email="*****@*****.**", locale="en") destination_user = CanvasUser( user_id=56789, name="J AVG USR", login_id="javerage", sis_user_id="15AE3883B6EC44C349E04E5FE089ABEB", email="*****@*****.**", locale="en") canvas.merge_users(user, destination_user) mock_merge.assert_called_with('/api/v1/users/12345/merge_into/56789')