예제 #1
0
 def test_project_get(self, kc):
     request = construct_request()
     kc.tenant_get.return_value.to_dict.return_value = {'name': 'Ni!'}
     response = keystone.Project().get(request, 'the_id')
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content, '{"name": "Ni!"}')
     kc.tenant_get.assert_called_once_with(request, 'the_id')
 def test_project_get(self, kc):
     request = construct_request()
     kc.tenant_get.return_value.to_dict.return_value = {'name': 'Ni!'}
     response = keystone.Project().get(request, 'the_id')
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content, '{"name": "Ni!"}')
     kc.tenant_get.assert_called_once_with(request, 'the_id')
예제 #3
0
 def test_user_get_current(self, kc):
     request = construct_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')
     kc.user_get.assert_not_called()
 def test_user_get_current(self, kc):
     request = construct_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')
     kc.user_get.assert_not_called()
 def test_role_get_default(self, kc):
     request = construct_request()
     kc.get_default_role.return_value.to_dict.return_value = {'name': 'Ni!'}
     response = keystone.Role().get(request, 'default')
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content, '{"name": "Ni!"}')
     kc.get_default_role.assert_called_once_with(request)
     kc.role_get.assert_not_called()
예제 #6
0
 def test_role_patch(self, kc):
     request = construct_request(body='{"name": "spam"}')
     response = keystone.Role().patch(request, 'the_id')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.role_update.assert_called_once_with(request,
                                            'the_id',
                                            'spam')
예제 #7
0
 def test_role_get_default(self, kc):
     request = construct_request()
     kc.get_default_role.return_value.to_dict.return_value = {'name': 'Ni!'}
     response = keystone.Role().get(request, 'default')
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content, '{"name": "Ni!"}')
     kc.get_default_role.assert_called_once_with(request)
     kc.role_get.assert_not_called()
 def test_domain_put(self, kc):
     request = construct_request(body='{"name": "spam"}')
     response = keystone.Domain().put(request, 'the_id')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.domain_update.assert_called_once_with(request,
                                              'the_id',
                                              name='spam',
                                              description=None,
                                              enabled=None)
예제 #9
0
 def test_user_patch_project(self, kc):
     request = construct_request(body='''
         {"project_id": "other123"}
     ''')
     response = keystone.User().patch(request, 'user123')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.user_update_tenant.assert_called_once_with(request,
                                                   'user123',
                                                   project='other123')
예제 #10
0
 def test_user_patch_password(self, kc):
     request = construct_request(body='''
         {"password": "******"}
     ''')
     response = keystone.User().patch(request, 'user123')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.user_update_password.assert_called_once_with(request,
                                                     'user123',
                                                     password='******')
 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)
예제 #12
0
 def test_user_patch_enabled(self, kc):
     request = construct_request(body='''
         {"enabled": false}
     ''')
     response = keystone.User().patch(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_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_role_grant(self, kc):
     request = construct_request(body='''
         {"action": "grant", "data": {"user_id": "user123",
         "role_id": "role123", "project_id": "project123"}}
     ''')
     response = keystone.Roles().post(request)
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.add_tenant_user_role.assert_called_once_with(
         request, 'project123', 'user123', 'role123')
 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='******')
예제 #16
0
 def test_domain_patch(self, kc):
     request = construct_request(body='{"name": "spam"}')
     response = keystone.Domain().patch(request, 'the_id')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.domain_update.assert_called_once_with(request,
                                              'the_id',
                                              name='spam',
                                              description=None,
                                              enabled=None)
예제 #17
0
 def test_role_grant(self, kc):
     request = construct_request(body='''
         {"action": "grant", "data": {"user_id": "user123",
         "role_id": "role123", "project_id": "project123"}}
     ''')
     response = keystone.ProjectRole().put(request, "project1", "role2",
                                           "user3")
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.add_tenant_user_role.assert_called_once_with(request, 'project1',
                                                     'user3', 'role2')
예제 #18
0
 def test_domain_get_list(self, kc):
     request = construct_request()
     kc.domain_list.return_value = [
         mock.Mock(**{'to_dict.return_value': {'name': 'Ni!'}}),
         mock.Mock(**{'to_dict.return_value': {'name': 'Ptang!'}})
     ]
     response = keystone.Domains().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content,
                      '{"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.domain_list.assert_called_once_with(request)
예제 #19
0
 def test_user_patch_multiple(self, kc):
     request = construct_request(body='''
         {"project_id": "other123", "enabled": false}
     ''')
     response = keystone.User().patch(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_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')
예제 #21
0
 def test_role_get_for_user(self, kc):
     request = construct_request(**{'GET': {'user_id': 'user123',
                                 'project_id': 'project123'}})
     kc.roles_for_user.return_value = [
         mock.Mock(**{'to_dict.return_value': {'name': 'Ni!'}}),
         mock.Mock(**{'to_dict.return_value': {'name': 'Ptang!'}})
     ]
     response = keystone.Roles().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content,
                      '{"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.roles_for_user.assert_called_once_with(request, 'user123',
                                               'project123')
예제 #22
0
    def test_project_delete_many(self, kc):
        request = construct_request(body='''
            ["id1", "id2", "id3"]
        ''')

        response = keystone.Projects().delete(request)
        self.assertStatusCode(response, 204)
        self.assertEqual(response.content, '')
        kc.tenant_delete.assert_has_mock.calls([
            mock.call(request, 'id1'),
            mock.call(request, 'id2'),
            mock.call(request, 'id3'),
        ])
예제 #23
0
 def test_project_get_list(self, kc):
     request = construct_request(**{'GET': {}})
     kc.tenant_list.return_value = ([
         mock.Mock(**{'to_dict.return_value': {'name': 'Ni!'}}),
         mock.Mock(**{'to_dict.return_value': {'name': 'Ptang!'}})
     ], False)
     with mock.patch.object(settings, 'DEBUG', True):
         response = keystone.Projects().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content, '{"has_more": false, '
                      '"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.tenant_list.assert_called_once_with(request, paginate=False,
                                            marker=None, domain=None,
                                            user=None, admin=True)
    def test_role_create(self, kc):
        request = construct_request(body='''
            {"action": "create", "data": {"name": "bob"}}
        ''')
        kc.role_create.return_value.id = 'role123'
        kc.role_create.return_value.to_dict.return_value = {
            'id': 'role123',
            'name': 'bob'
        }

        response = keystone.Roles().post(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'], '/api/keystone/roles/role123')
        self.assertEqual(response.content, '{"id": "role123", "name": "bob"}')
        kc.role_create.assert_called_once_with(request, 'bob')
예제 #25
0
    def test_role_create(self, kc):
        request = construct_request(body='''
            {"name": "bob"}
        ''')
        kc.role_create.return_value.id = 'role123'
        kc.role_create.return_value.to_dict.return_value = {
            'id': 'role123', 'name': 'bob'
        }

        response = keystone.Roles().post(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'],
                         '/api/keystone/roles/role123')
        self.assertEqual(response.content, '{"id": "role123", "name": "bob"}')
        kc.role_create.assert_called_once_with(request, 'bob')
 def test_domain_get_list(self, kc):
     request = construct_request()
     kc.domain_list.return_value = [
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ni!'
         }}),
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ptang!'
         }})
     ]
     response = keystone.Domains().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content,
                      '{"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.domain_list.assert_called_once_with(request)
예제 #27
0
 def test_project_patch(self, kc):
     # nothing in the Horizon code documents what additional parameters are
     # allowed, so we'll just assume GIGO
     request = construct_request(body='''
         {"name": "spam", "domain_id": "domain123", "foo": "bar"}
     ''')
     response = keystone.Project().patch(request, 'spam123')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.tenant_update.assert_called_once_with(request,
                                              'spam123',
                                              name='spam', foo='bar',
                                              description=None,
                                              domain='domain123',
                                              enabled=None)
예제 #28
0
 def test_user_get_list(self, kc):
     request = construct_request(**{
         'session.get': mock.Mock(return_value='the_domain'),
         'GET': {},
     })
     kc.user_list.return_value = [
         mock.Mock(**{'to_dict.return_value': {'name': 'Ni!'}}),
         mock.Mock(**{'to_dict.return_value': {'name': 'Ptang!'}})
     ]
     response = keystone.Users().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content,
                      '{"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.user_list.assert_called_once_with(request, project=None,
                                          domain='the_domain', group=None)
예제 #29
0
    def _test_project_create(self, supplied_body, expected_call, kc):
        request = construct_request(body=supplied_body)
        kc.tenant_create.return_value.id = 'project123'
        kc.tenant_create.return_value.to_dict.return_value = {
            'id': 'project123', 'name': 'bob'
        }

        response = keystone.Projects().post(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'],
                         '/api/keystone/projects/project123')
        self.assertEqual(response.content, '{"id": "project123", '
                         '"name": "bob"}')
        kc.tenant_create.assert_called_once_with(request, 'bob',
                                                 **expected_call)
 def test_project_put(self, kc):
     # nothing in the Horizon code documents what additional parameters are
     # allowed, so we'll just assume GIGO
     request = construct_request(body='''
         {"name": "spam", "domain_id": "domain123", "foo": "bar"}
     ''')
     response = keystone.Project().put(request, 'spam123')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.tenant_update.assert_called_once_with(request,
                                              'spam123',
                                              name='spam',
                                              foo='bar',
                                              description=None,
                                              domain='domain123',
                                              enabled=None)
예제 #31
0
    def _test_user_create(self, supplied_body, expected_call, kc):
        request = construct_request(body=supplied_body)
        kc.get_default_domain.return_value = mock.Mock(**{'id': 'the_domain'})
        kc.user_create.return_value.id = 'user123'
        kc.user_create.return_value = mock.Mock(**{
            'id': 'user123',
            'to_dict.return_value': {'id': 'user123', 'name': 'bob'}
        })

        response = keystone.Users().post(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'],
                         '/api/keystone/users/user123')
        self.assertEqual(response.content, '{"id": "user123", '
                         '"name": "bob"}')
        kc.user_create.assert_called_once_with(request, **expected_call)
    def test_project_delete_many(self, kc):
        request = construct_request(body='''
            {
                "action": "delete",
                "data": ["id1", "id2", "id3"]
            }
        ''')

        response = keystone.Projects().post(request)
        self.assertStatusCode(response, 204)
        self.assertEqual(response.content, '')
        kc.tenant_delete.assert_has_mock.calls([
            mock.call(request, 'id1'),
            mock.call(request, 'id2'),
            mock.call(request, 'id3'),
        ])
    def _test_project_create(self, supplied_body, expected_call, kc):
        request = construct_request(body=supplied_body)
        kc.tenant_create.return_value.id = 'project123'
        kc.tenant_create.return_value.to_dict.return_value = {
            'id': 'project123',
            'name': 'bob'
        }

        response = keystone.Projects().post(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'],
                         '/api/keystone/projects/project123')
        self.assertEqual(response.content, '{"id": "project123", '
                         '"name": "bob"}')
        kc.tenant_create.assert_called_once_with(request, 'bob',
                                                 **expected_call)
    def _test_user_create(self, supplied_body, expected_call, kc):
        request = construct_request(body=supplied_body)
        kc.get_default_domain.return_value = mock.Mock(**{'id': 'the_domain'})
        kc.user_create.return_value.id = 'user123'
        kc.user_create.return_value = mock.Mock(
            **{
                'id': 'user123',
                'to_dict.return_value': {
                    'id': 'user123',
                    'name': 'bob'
                }
            })

        response = keystone.Users().post(request)
        self.assertStatusCode(response, 201)
        self.assertEqual(response['location'], '/api/keystone/users/user123')
        self.assertEqual(response.content, '{"id": "user123", '
                         '"name": "bob"}')
        kc.user_create.assert_called_once_with(request, **expected_call)
 def test_role_get_for_user(self, kc):
     request = construct_request(
         **{'GET': {
             'user_id': 'user123',
             'project_id': 'project123'
         }})
     kc.roles_for_user.return_value = [
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ni!'
         }}),
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ptang!'
         }})
     ]
     response = keystone.Roles().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content,
                      '{"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.roles_for_user.assert_called_once_with(request, 'user123',
                                               'project123')
 def test_user_get_list(self, kc):
     request = construct_request(
         **{
             'session.get': mock.Mock(return_value='the_domain'),
             'GET': {},
         })
     kc.user_list.return_value = [
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ni!'
         }}),
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ptang!'
         }})
     ]
     response = keystone.Users().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content,
                      '{"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.user_list.assert_called_once_with(request,
                                          project=None,
                                          domain='the_domain',
                                          group=None)
 def test_project_get_list(self, kc):
     request = construct_request(**{'GET': {}})
     kc.tenant_list.return_value = ([
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ni!'
         }}),
         mock.Mock(**{'to_dict.return_value': {
             'name': 'Ptang!'
         }})
     ], False)
     with mock.patch.object(settings, 'DEBUG', True):
         response = keystone.Projects().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(
         response.content, '{"has_more": false, '
         '"items": [{"name": "Ni!"}, {"name": "Ptang!"}]}')
     kc.tenant_list.assert_called_once_with(request,
                                            paginate=False,
                                            marker=None,
                                            domain=None,
                                            user=None,
                                            admin=True)
 def test_project_delete(self, kc):
     request = construct_request()
     response = keystone.Project().delete(request, 'the_id')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.tenant_delete.assert_called_once_with(request, 'the_id')
예제 #39
0
 def test_project_delete(self, kc):
     request = construct_request()
     response = keystone.Project().delete(request, 'the_id')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.tenant_delete.assert_called_once_with(request, 'the_id')
 def test_role_put(self, kc):
     request = construct_request(body='{"name": "spam"}')
     response = keystone.Role().put(request, 'the_id')
     self.assertStatusCode(response, 204)
     self.assertEqual(response.content, '')
     kc.role_update.assert_called_once_with(request, 'the_id', 'spam')