~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/v3/test_users.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-18 07:44:54 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20130118074454-g7w5blpynohn1s48
Tags: 1:0.2.2-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 OpenStack LLC
 
4
#
 
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
# not use this file except in compliance with the License. You may obtain
 
7
# a copy of the License at
 
8
#
 
9
#      http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
# Unless required by applicable law or agreed to in writing, software
 
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
# License for the specific language governing permissions and limitations
 
15
# under the License.
 
16
 
 
17
import copy
 
18
import urlparse
1
19
import uuid
2
20
 
 
21
import requests
 
22
 
3
23
from keystoneclient.v3 import users
4
24
from tests.v3 import utils
5
25
 
21
41
        kwargs.setdefault('name', uuid.uuid4().hex)
22
42
        kwargs.setdefault('project_id', uuid.uuid4().hex)
23
43
        return kwargs
 
44
 
 
45
    def test_add_user_to_group(self):
 
46
        group_id = uuid.uuid4().hex
 
47
        ref = self.new_ref()
 
48
        resp = utils.TestResponse({
 
49
            "status_code": 204,
 
50
            "text": '',
 
51
        })
 
52
 
 
53
        method = 'PUT'
 
54
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
 
55
        kwargs['headers'] = self.headers[method]
 
56
        requests.request(
 
57
            method,
 
58
            urlparse.urljoin(
 
59
                self.TEST_URL,
 
60
                'v3/groups/%s/%s/%s' % (
 
61
                    group_id, self.collection_key, ref['id'])),
 
62
            **kwargs).AndReturn((resp))
 
63
        self.mox.ReplayAll()
 
64
 
 
65
        self.manager.add_to_group(user=ref['id'], group=group_id)
 
66
 
 
67
    def test_list_users_in_group(self):
 
68
        group_id = uuid.uuid4().hex
 
69
        ref_list = [self.new_ref(), self.new_ref()]
 
70
        resp = utils.TestResponse({
 
71
            "status_code": 200,
 
72
            "text": self.serialize(ref_list),
 
73
        })
 
74
 
 
75
        method = 'GET'
 
76
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
 
77
        kwargs['headers'] = self.headers[method]
 
78
        requests.request(
 
79
            method,
 
80
            urlparse.urljoin(
 
81
                self.TEST_URL,
 
82
                'v3/groups/%s/%s' % (
 
83
                    group_id, self.collection_key)),
 
84
            **kwargs).AndReturn((resp))
 
85
        self.mox.ReplayAll()
 
86
 
 
87
        returned_list = self.manager.list(group=group_id)
 
88
        self.assertTrue(len(returned_list))
 
89
        [self.assertTrue(isinstance(r, self.model)) for r in returned_list]
 
90
 
 
91
    def test_check_user_in_group(self):
 
92
        group_id = uuid.uuid4().hex
 
93
        ref = self.new_ref()
 
94
        resp = utils.TestResponse({
 
95
            "status_code": 204,
 
96
            "text": '',
 
97
        })
 
98
 
 
99
        method = 'HEAD'
 
100
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
 
101
        kwargs['headers'] = self.headers[method]
 
102
        requests.request(
 
103
            method,
 
104
            urlparse.urljoin(
 
105
                self.TEST_URL,
 
106
                'v3/groups/%s/%s/%s' % (
 
107
                    group_id, self.collection_key, ref['id'])),
 
108
            **kwargs).AndReturn((resp))
 
109
        self.mox.ReplayAll()
 
110
 
 
111
        self.manager.check_in_group(user=ref['id'], group=group_id)
 
112
 
 
113
    def test_remove_user_from_group(self):
 
114
        group_id = uuid.uuid4().hex
 
115
        ref = self.new_ref()
 
116
        resp = utils.TestResponse({
 
117
            "status_code": 204,
 
118
            "text": '',
 
119
        })
 
120
 
 
121
        method = 'DELETE'
 
122
        kwargs = copy.copy(self.TEST_REQUEST_BASE)
 
123
        kwargs['headers'] = self.headers[method]
 
124
        requests.request(
 
125
            method,
 
126
            urlparse.urljoin(
 
127
                self.TEST_URL,
 
128
                'v3/groups/%s/%s/%s' % (
 
129
                    group_id, self.collection_key, ref['id'])),
 
130
            **kwargs).AndReturn((resp))
 
131
        self.mox.ReplayAll()
 
132
 
 
133
        self.manager.remove_from_group(user=ref['id'], group=group_id)