def test_delete_user_bossadmin(self, mKCC): ctxMgr = mKCC.return_value.__enter__.return_value request = self.makeRequest(delete='/' + version + '/sso/user/bossadmin') response = BossUser.as_view()(request, 'bossadmin') self.assertEqual(response.status_code, 500)
def test_post_user(self, mKCC): ctxMgr = mKCC.return_value.__enter__.return_value data = { 'first_name': 'first', 'last_name': 'last', 'email': 'email', 'password': '******' } request = self.makeRequest(post='/' + version + '/sso/user/test', data=data) response = BossUser.as_view()(request, 'test') self.assertEqual(response.status_code, 201) self.assertIsNone(response.data) call1 = mock.call.create_user( json.dumps({ 'username': '******', 'firstName': 'first', 'lastName': 'last', 'email': 'email', 'enabled': True })) call2 = mock.call.reset_password('test', { 'type': 'password', 'temporary': False, 'value': 'password' }) self.assertEqual(ctxMgr.mock_calls, [call1, call2])
def test_failed_post_user_rollback(self, mKCC): ctxMgr = mKCC.return_value.__enter__.return_value ctxMgr.reset_password.side_effect = raise_error data = { 'first_name': 'first', 'last_name': 'last', 'email': 'email', 'password': '******' } request = self.makeRequest(post='/' + version + '/sso/user/test', data=data) response = BossUser.as_view()(request, 'test') self.assertEqual(response.status_code, 500) call1 = mock.call.create_user( json.dumps({ 'username': '******', 'firstName': 'first', 'lastName': 'last', 'email': 'email', 'enabled': True })) call2 = mock.call.reset_password('test', { 'type': 'password', 'temporary': False, 'value': 'password' }) call3 = mock.call.delete_user('test') # make sure the user is deleted self.assertEqual(ctxMgr.mock_calls, [call1, call2, call3])
def test_failed_post_user(self, mKCC): ctxMgr = mKCC.return_value.__enter__.return_value ctxMgr.create_user.side_effect = raise_error request = self.makeRequest(post='/' + version + '/sso/user/test', data={}) response = BossUser.as_view()(request, 'test') self.assertEqual(response.status_code, 500)
def test_failed_get_user(self, mKCC): ctxMgr = mKCC.return_value.__enter__.return_value ctxMgr.get_userdata.side_effect = raise_error request = self.makeRequest(get='/v0.6/sso/user/test') response = BossUser.as_view()(request, 'test') self.assertEqual(response.status_code, 500)
def test_delete_user(self, mKCC): ctxMgr = mKCC.return_value.__enter__.return_value request = self.makeRequest(delete='/' + version + '/sso/user/test') response = BossUser.as_view()(request, 'test') self.assertEqual(response.status_code, 204) self.assertIsNone(response.data) call = mock.call.delete_user('test') self.assertEqual(ctxMgr.mock_calls, [call])
def test_get_user(self, mKCC): ctxMgr = mKCC.return_value.__enter__.return_value ctxMgr.get_userdata.return_value = {'name':'test'} ctxMgr.get_realm_roles.return_value = [{'name': 'test'},{'name': 'admin'}] request = self.makeRequest(get='/' + version + '/sso/user/test') response = BossUser.as_view()(request, 'test') # arguments are not parsed out self.assertEqual(response.status_code, 200) # Role 'test' will be filtered out by the view data = {'name':'test', 'realmRoles':['admin']} self.assertEqual(response.data, data) call1 = mock.call.get_userdata('test') call2 = mock.call.get_realm_roles('test') self.assertEqual(ctxMgr.mock_calls, [call1, call2])