root / kamaki / clients / livetest / astakos.py @ 45a3721b
History | View | Annotate | Download (5.2 kB)
1 |
# Copyright 2012-2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
from itertools import product |
35 |
|
36 |
from kamaki.clients import livetest, ClientError |
37 |
from kamaki.clients.astakos import AstakosClient |
38 |
|
39 |
|
40 |
class Astakos(livetest.Generic): |
41 |
def setUp(self): |
42 |
self.cloud = 'cloud.%s' % self['testcloud'] |
43 |
self.client = AstakosClient(
|
44 |
self[self.cloud, 'url'], self[self.cloud, 'token']) |
45 |
print 'WHA?', self['astakos', 'details'] |
46 |
with open(self['astakos', 'details']) as f: |
47 |
self._astakos_details = eval(f.read()) |
48 |
|
49 |
def test_authenticate(self): |
50 |
self._test_0010_authenticate()
|
51 |
|
52 |
def _test_0010_authenticate(self): |
53 |
r = self.client.authenticate()
|
54 |
self.assert_dicts_are_equal(r, self._astakos_details) |
55 |
|
56 |
def test_get_services(self): |
57 |
self._test_0020_get_services()
|
58 |
|
59 |
def _test_0020_get_services(self): |
60 |
for args in (tuple(), (self[self.cloud, 'token'],)): |
61 |
r = self.client.get_services(*args)
|
62 |
services = self._astakos_details['access']['serviceCatalog'] |
63 |
self.assertEqual(len(services), len(r)) |
64 |
for i, service in enumerate(services): |
65 |
self.assert_dicts_are_equal(r[i], service)
|
66 |
self.assertRaises(ClientError, self.client.get_services, 'wrong_token') |
67 |
|
68 |
def test_get_service_details(self): |
69 |
self._test_0020_get_service_details()
|
70 |
|
71 |
def _test_0020_get_service_details(self): |
72 |
parsed_services = dict()
|
73 |
for args in product( |
74 |
self._astakos_details['access']['serviceCatalog'], |
75 |
([tuple(), (self[self.cloud, 'token'],)])): |
76 |
service = args[0]
|
77 |
if service['type'] in parsed_services: |
78 |
continue
|
79 |
r = self.client.get_service_details(service['type'], *args[1]) |
80 |
self.assert_dicts_are_equal(r, service)
|
81 |
parsed_services[service['type']] = True |
82 |
self.assertRaises(
|
83 |
ClientError, self.client.get_service_details, 'wrong_token') |
84 |
|
85 |
def test_get_service_endpoints(self): |
86 |
self._test_0020_get_service_endpoints()
|
87 |
|
88 |
def _test_0020_get_service_endpoints(self): |
89 |
parsed_services = dict()
|
90 |
for args in product( |
91 |
self._astakos_details['access']['serviceCatalog'], |
92 |
([], [self[self.cloud, 'token']])): |
93 |
service = args[0]
|
94 |
if service['type'] in parsed_services: |
95 |
continue
|
96 |
for endpoint, with_id in product( |
97 |
service['endpoints'], (True, False)): |
98 |
vid = endpoint['versionId'] if ( |
99 |
with_id and endpoint['versionId']) else None |
100 |
end_args = [service['type'], vid] + args[1] |
101 |
r = self.client.get_service_endpoints(*end_args)
|
102 |
self.assert_dicts_are_equal(r, endpoint)
|
103 |
parsed_services[service['type']] = True |
104 |
self.assertRaises(
|
105 |
ClientError, self.client.get_service_endpoints, 'wrong_token') |
106 |
|
107 |
def test_user_info(self): |
108 |
self._test_0020_user_info()
|
109 |
|
110 |
def _test_0020_user_info(self): |
111 |
self.assertTrue(set([ |
112 |
'roles',
|
113 |
'name',
|
114 |
'id']).issubset(self.client.user_info().keys())) |
115 |
|
116 |
def test_get(self): |
117 |
self._test_0020_get()
|
118 |
|
119 |
def _test_0020_get(self): |
120 |
for term in ('id', 'name'): |
121 |
self.assertEqual(
|
122 |
self.client.term(term, self[self.cloud, 'token']), |
123 |
self['astakos', term] or '') |
124 |
|
125 |
def test_list_users(self): |
126 |
self.client.authenticate()
|
127 |
self._test_0020_list_users()
|
128 |
|
129 |
def _test_0020_list_users(self): |
130 |
terms = set(['name', 'id']) |
131 |
uuid = 0
|
132 |
for r in self.client.list_users(): |
133 |
self.assertTrue(terms.issubset(r.keys()))
|
134 |
self.assertTrue(uuid != r['id'] if uuid else True) |
135 |
uuid = r['id']
|