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

« back to all changes in this revision

Viewing changes to tests/test_shell.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 12:34:22 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120816123422-hw1qunw9j19gixpa
Tags: 1:0.1.2-0ubuntu1
* New upstream release.
* debian/watch: Updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
            expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
61
61
                      DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
62
62
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
63
 
 
64
            # Old_style options
63
65
            shell('--os_auth_url http://0.0.0.0:5000/ --os_password xyzpdq '
64
66
                  '--os_tenant_id 1234 --os_tenant_name fred '
65
67
                  '--os_username barney '
73
75
                      'fred', 'barney', '2.0')
74
76
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
75
77
 
 
78
            # New-style options
 
79
            shell('--os-auth-url http://1.1.1.1:5000/ --os-password xyzpdq '
 
80
                  '--os-tenant-id 4321 --os-tenant-name wilma '
 
81
                  '--os-username betty '
 
82
                  '--os-identity-api-version 2.0 user-list')
 
83
            assert do_tenant_mock.called
 
84
            ((a, b), c) = do_tenant_mock.call_args
 
85
            actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
 
86
                      b.os_tenant_name, b.os_username,
 
87
                      b.os_identity_api_version)
 
88
            expect = ('http://1.1.1.1:5000/', 'xyzpdq', '4321',
 
89
                      'wilma', 'betty', '2.0')
 
90
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
91
 
76
92
    def test_shell_user_create_args(self):
77
93
        """Test user-create args"""
78
94
        do_uc_mock = mock.MagicMock()
82
98
        with mock.patch('keystoneclient.v2_0.shell.do_user_create',
83
99
                        do_uc_mock):
84
100
 
 
101
            # Old_style options
85
102
            # Test case with one --tenant_id args present: ec2 creds
86
103
            shell('user-create --name=FOO '
87
104
                  '--pass=secrete --tenant_id=barrr --enabled=true')
97
114
            expect = ('barrr', 'FOO', 'secrete', 'true')
98
115
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
99
116
 
 
117
            # New-style options
 
118
            # Test case with one --tenant-id args present: ec2 creds
 
119
            shell('user-create --name=foo '
 
120
                  '--pass=secrete --tenant-id=BARRR --enabled=true')
 
121
            assert do_uc_mock.called
 
122
            ((a, b), c) = do_uc_mock.call_args
 
123
            actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
 
124
                      b.os_tenant_name, b.os_username,
 
125
                      b.os_identity_api_version)
 
126
            expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
 
127
                      DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
 
128
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
129
            actual = (b.tenant_id, b.name, b.passwd, b.enabled)
 
130
            expect = ('BARRR', 'foo', 'secrete', 'true')
 
131
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
132
 
 
133
            # Old_style options
100
134
            # Test case with --os_tenant_id and --tenant_id args present
101
135
            shell('--os_tenant_id=os-tenant user-create --name=FOO '
102
136
                  '--pass=secrete --tenant_id=barrr --enabled=true')
112
146
            expect = ('barrr', 'FOO', 'secrete', 'true')
113
147
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
114
148
 
 
149
            # New-style options
 
150
            # Test case with --os-tenant-id and --tenant-id args present
 
151
            shell('--os-tenant-id=ostenant user-create --name=foo '
 
152
                  '--pass=secrete --tenant-id=BARRR --enabled=true')
 
153
            assert do_uc_mock.called
 
154
            ((a, b), c) = do_uc_mock.call_args
 
155
            actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
 
156
                      b.os_tenant_name, b.os_username,
 
157
                      b.os_identity_api_version)
 
158
            expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'ostenant',
 
159
                      DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
 
160
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
161
            actual = (b.tenant_id, b.name, b.passwd, b.enabled)
 
162
            expect = ('BARRR', 'foo', 'secrete', 'true')
 
163
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
164
 
115
165
    def test_do_tenant_create(self):
116
166
        do_tenant_mock = mock.MagicMock()
117
167
        with mock.patch('keystoneclient.v2_0.shell.do_tenant_create',
140
190
        with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_create',
141
191
                        do_ec2_mock):
142
192
 
 
193
            # Old_style options
143
194
            # Test case with one --tenant_id args present: ec2 creds
144
195
            shell('ec2-credentials-create '
145
196
                  '--tenant_id=ec2-tenant --user_id=ec2-user')
155
206
            expect = ('ec2-tenant', 'ec2-user')
156
207
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
157
208
 
 
209
            # New-style options
 
210
            # Test case with one --tenant-id args present: ec2 creds
 
211
            shell('ec2-credentials-create '
 
212
                  '--tenant-id=dash-tenant --user-id=dash-user')
 
213
            assert do_ec2_mock.called
 
214
            ((a, b), c) = do_ec2_mock.call_args
 
215
            actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
 
216
                      b.os_tenant_name, b.os_username,
 
217
                      b.os_identity_api_version)
 
218
            expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
 
219
                      DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
 
220
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
221
            actual = (b.tenant_id, b.user_id)
 
222
            expect = ('dash-tenant', 'dash-user')
 
223
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
224
 
 
225
            # Old_style options
158
226
            # Test case with two --tenant_id args present
159
227
            shell('--os_tenant_id=os-tenant ec2-credentials-create '
160
228
                  '--tenant_id=ec2-tenant --user_id=ec2-user')
170
238
            expect = ('ec2-tenant', 'ec2-user')
171
239
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
172
240
 
 
241
            # New-style options
 
242
            # Test case with two --tenant-id args present
 
243
            shell('--os-tenant-id=ostenant ec2-credentials-create '
 
244
                  '--tenant-id=dash-tenant --user-id=dash-user')
 
245
            assert do_ec2_mock.called
 
246
            ((a, b), c) = do_ec2_mock.call_args
 
247
            actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
 
248
                      b.os_tenant_name, b.os_username,
 
249
                      b.os_identity_api_version)
 
250
            expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'ostenant',
 
251
                      DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
 
252
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
253
            actual = (b.tenant_id, b.user_id)
 
254
            expect = ('dash-tenant', 'dash-user')
 
255
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
256
 
173
257
    def test_do_ec2_get(self):
174
258
        do_shell_mock = mock.MagicMock()
175
259
 
201
285
        with mock.patch('keystoneclient.v2_0.shell.do_endpoint_create',
202
286
                        do_shell_mock):
203
287
 
 
288
            # Old_style options
204
289
            # Test create args
205
290
            shell('endpoint-create '
206
291
                  '--service_id=2 --publicurl=http://example.com:1234/go '
218
303
                      'http://example.com:1234/go',
219
304
                      'http://example.com:9876/adm')
220
305
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
306
 
 
307
            # New-style options
 
308
            # Test create args
 
309
            shell('endpoint-create '
 
310
                  '--service-id=3 --publicurl=http://example.com:4321/go '
 
311
                  '--adminurl=http://example.com:9876/adm')
 
312
            assert do_shell_mock.called
 
313
            ((a, b), c) = do_shell_mock.call_args
 
314
            actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
 
315
                      b.os_tenant_name, b.os_username,
 
316
                      b.os_identity_api_version)
 
317
            expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
 
318
                      DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
 
319
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
 
320
            actual = (b.service_id, b.publicurl, b.adminurl)
 
321
            expect = ('3',
 
322
                      'http://example.com:4321/go',
 
323
                      'http://example.com:9876/adm')
 
324
            self.assertTrue(all([x == y for x, y in zip(actual, expect)]))