root / kamaki / clients / livetest / astakos.py @ c6ebe715
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 |
with open(self['astakos', 'details']) as f: |
46 |
self._astakos_details = eval(f.read()) |
47 |
|
48 |
def test_authenticate(self): |
49 |
self._test_0010_authenticate()
|
50 |
|
51 |
def _test_0010_authenticate(self): |
52 |
r = self.client.authenticate()
|
53 |
self.assert_dicts_are_equal(r, self._astakos_details) |
54 |
|
55 |
def test_get_services(self): |
56 |
self._test_0020_get_services()
|
57 |
|
58 |
def _test_0020_get_services(self): |
59 |
for args in (tuple(), (self[self.cloud, 'token'],)): |
60 |
r = self.client.get_services(*args)
|
61 |
services = self._astakos_details['access']['serviceCatalog'] |
62 |
self.assertEqual(len(services), len(r)) |
63 |
for i, service in enumerate(services): |
64 |
self.assert_dicts_are_equal(r[i], service)
|
65 |
self.assertRaises(ClientError, self.client.get_services, 'wrong_token') |
66 |
|
67 |
def test_get_service_details(self): |
68 |
self._test_0020_get_service_details()
|
69 |
|
70 |
def _test_0020_get_service_details(self): |
71 |
parsed_services = dict()
|
72 |
for args in product( |
73 |
self._astakos_details['access']['serviceCatalog'], |
74 |
([tuple(), (self[self.cloud, 'token'],)])): |
75 |
service = args[0]
|
76 |
if service['type'] in parsed_services: |
77 |
continue
|
78 |
r = self.client.get_service_details(service['type'], *args[1]) |
79 |
self.assert_dicts_are_equal(r, service)
|
80 |
parsed_services[service['type']] = True |
81 |
self.assertRaises(
|
82 |
ClientError, self.client.get_service_details, 'wrong_token') |
83 |
|
84 |
def test_get_service_endpoints(self): |
85 |
self._test_0020_get_service_endpoints()
|
86 |
|
87 |
def _test_0020_get_service_endpoints(self): |
88 |
parsed_services = dict()
|
89 |
for args in product( |
90 |
self._astakos_details['access']['serviceCatalog'], |
91 |
([], [self[self.cloud, 'token']])): |
92 |
service = args[0]
|
93 |
if service['type'] in parsed_services: |
94 |
continue
|
95 |
for endpoint, with_id in product( |
96 |
service['endpoints'], (True, False)): |
97 |
vid = endpoint['versionId'] if ( |
98 |
with_id and endpoint['versionId']) else None |
99 |
end_args = [service['type'], vid] + args[1] |
100 |
r = self.client.get_service_endpoints(*end_args)
|
101 |
self.assert_dicts_are_equal(r, endpoint)
|
102 |
parsed_services[service['type']] = True |
103 |
self.assertRaises(
|
104 |
ClientError, self.client.get_service_endpoints, 'wrong_token') |
105 |
|
106 |
def test_user_info(self): |
107 |
self._test_0020_user_info()
|
108 |
|
109 |
def _test_0020_user_info(self): |
110 |
self.assertTrue(set([ |
111 |
'roles',
|
112 |
'name',
|
113 |
'id']).issubset(self.client.user_info().keys())) |
114 |
|
115 |
def test_get(self): |
116 |
self._test_0020_get()
|
117 |
|
118 |
def _test_0020_get(self): |
119 |
for term in ('id', 'name'): |
120 |
self.assertEqual(
|
121 |
self.client.term(term, self[self.cloud, 'token']), |
122 |
self['astakos', term] or '') |
123 |
|
124 |
def test_list_users(self): |
125 |
self.client.authenticate()
|
126 |
self._test_0020_list_users()
|
127 |
|
128 |
def _test_0020_list_users(self): |
129 |
terms = set(['name', 'id']) |
130 |
uuid = 0
|
131 |
for r in self.client.list_users(): |
132 |
self.assertTrue(terms.issubset(r.keys()))
|
133 |
self.assertTrue(uuid != r['id'] if uuid else True) |
134 |
uuid = r['id']
|