def test_user_get(self, kc): request = construct_request() kc.user_get.return_value.to_dict.return_value = {'name': 'Ni!'} response = keystone.User().get(request, 'the_id') self.assertStatusCode(response, 200) self.assertEqual(response.content, '{"name": "Ni!"}') kc.user_get.assert_called_once_with(request, 'the_id')
def test_user_delete(self): request = self.mock_rest_request() self.mock_user_delete.return_value = None response = keystone.User().delete(request, 'the_id') self.assertStatusCode(response, 204) self.assertEqual(response.content, b'') self.mock_user_delete.assert_called_once_with(request, 'the_id')
def test_user_get_current(self, kc): request = self.mock_rest_request(**{'user.id': 'current_id'}) kc.user_get.return_value.to_dict.return_value = {'name': 'Ni!'} response = keystone.User().get(request, 'current') self.assertStatusCode(response, 200) self.assertEqual(response.content, '{"name": "Ni!"}') kc.user_get.assert_called_once_with(request, 'current_id')
def test_user_get(self): request = self.mock_rest_request() self.mock_user_get.return_value.to_dict.return_value = {'name': 'Ni!'} response = keystone.User().get(request, 'the_id') self.assertStatusCode(response, 200) self.assertEqual(response.json, {"name": "Ni!"}) self.mock_user_get.assert_called_once_with(request, 'the_id')
def test_user_put_project(self, kc): request = construct_request(body=''' {"project_id": "other123"} ''') response = keystone.User().put(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_update_tenant.assert_called_once_with(request, 'user123', project='other123')
def test_user_put_enabled(self, kc): request = construct_request(body=''' {"enabled": false} ''') response = keystone.User().put(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_update_enabled.assert_called_once_with(request, 'user123', enabled=False)
def test_user_put_password(self, kc): request = construct_request(body=''' {"password": "******"} ''') response = keystone.User().put(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_update_password.assert_called_once_with(request, 'user123', password='******')
def test_user_patch_enabled(self, kc): request = self.mock_rest_request(body=''' {"enabled": false} ''') user = keystone.User() kc.user_get = mock.MagicMock(return_value=user) response = user.patch(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_get.assert_called_once_with(request, 'user123') kc.user_update_enabled.assert_called_once_with(request, user, False)
def test_user_patch_password(self, kc): request = self.mock_rest_request(body=''' {"password": "******"} ''') user = keystone.User() kc.user_get = mock.MagicMock(return_value=user) response = user.patch(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_update_password.assert_called_once_with( request, user, 'sekrit')
def test_user_put_multiple(self, kc): request = construct_request(body=''' {"project_id": "other123", "enabled": false} ''') response = keystone.User().put(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_update.assert_called_once_with(request, 'user123', enabled=False, password=None, project='other123')
def test_user_patch_project(self, kc): request = self.mock_rest_request(body=''' {"project": "other123"} ''') user = keystone.User() kc.user_get = mock.MagicMock(return_value=user) response = user.patch(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_update.assert_called_once_with(request, user, project='other123')
def test_user_patch_enabled(self): request = self.mock_rest_request(body=''' {"enabled": false} ''') user = keystone.User() self.mock_user_get.return_value = mock.sentinel.user self.mock_user_update_enabled.return_value = None response = user.patch(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, b'') self.mock_user_get.assert_called_once_with(request, 'user123') self.mock_user_update_enabled.assert_called_once_with( request, mock.sentinel.user, False)
def test_user_patch_multiple(self): request = self.mock_rest_request(body=''' {"project": "other123", "name": "something"} ''') user = keystone.User() self.mock_user_get.return_value = mock.sentinel.user self.mock_user_update.return_value = self.users.first() response = user.patch(request, 'user123') self.assertStatusCode(response, 204) self.assertEqual(response.content, b'') self.mock_user_get.assert_called_once_with(request, 'user123') self.mock_user_update.assert_called_once_with( request, mock.sentinel.user, project='other123', name='something')
def test_user_delete(self, kc): request = construct_request() response = keystone.User().delete(request, 'the_id') self.assertStatusCode(response, 204) self.assertEqual(response.content, '') kc.user_delete.assert_called_once_with(request, 'the_id')