root / kamaki / cli / commands / test_cli.py @ 5207c784
History | View | Annotate | Download (6.7 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.command
|
33 |
|
34 |
from kamaki.cli.commands import errors |
35 |
from kamaki.cli import command |
36 |
from kamaki.cli.commands import _command_init |
37 |
from kamaki.cli.command_tree import CommandTree |
38 |
from kamaki.clients import tests |
39 |
from kamaki.cli.errors import raiseCLIError |
40 |
|
41 |
test_cmds = CommandTree('test', 'Unitest clients') |
42 |
_commands = [test_cmds] |
43 |
|
44 |
|
45 |
class _test_init(_command_init): |
46 |
|
47 |
def _run(self, client, method=None): |
48 |
if method:
|
49 |
tests._main([client, method], config=self.config)
|
50 |
else:
|
51 |
tests._main([client], config=self.config)
|
52 |
|
53 |
def main(self, client, method=None): |
54 |
return self._run(client, method) |
55 |
|
56 |
|
57 |
@command(test_cmds)
|
58 |
class test_error(_test_init): |
59 |
"""Create an error message with optional message"""
|
60 |
|
61 |
@errors.generic.all
|
62 |
def _run(self, errmsg='', importance=0, index=0): |
63 |
l = [1, 2] |
64 |
try:
|
65 |
l[int(index)]
|
66 |
except Exception as err: |
67 |
raiseCLIError(err, errmsg, importance) |
68 |
raiseCLIError(None, errmsg, importance)
|
69 |
|
70 |
def main(self, errmsg='', importance=0, index=0): |
71 |
self._run(errmsg, importance, index)
|
72 |
|
73 |
|
74 |
@command(test_cmds)
|
75 |
class test_args(_test_init): |
76 |
"""Test how arguments are treated by kamaki"""
|
77 |
|
78 |
@errors.generic.all
|
79 |
def _run(self, *args): |
80 |
print(args) |
81 |
|
82 |
def main(self, *args): |
83 |
self._run(args)
|
84 |
|
85 |
|
86 |
@command(test_cmds)
|
87 |
class test_all(_test_init): |
88 |
"""test all clients"""
|
89 |
|
90 |
@errors.generic.all
|
91 |
def _run(self): |
92 |
for client in ('pithos', 'cyclades', 'image', 'astakos'): |
93 |
super(self.__class__, self)._run(client) |
94 |
|
95 |
def main(self): |
96 |
self._run()
|
97 |
|
98 |
|
99 |
@command(test_cmds)
|
100 |
class test_pithos(_test_init): |
101 |
""" test Pithos client"""
|
102 |
|
103 |
@errors.generic.all
|
104 |
def _run(self, method=None): |
105 |
super(self.__class__, self)._run('pithos', method) |
106 |
|
107 |
def main(self, method=None): |
108 |
self._run(method)
|
109 |
|
110 |
|
111 |
@command(test_cmds)
|
112 |
class test_cyclades(_test_init): |
113 |
""" test Cyclades client"""
|
114 |
|
115 |
@errors.generic.all
|
116 |
def _run(self, method=None): |
117 |
super(self.__class__, self)._run('cyclades', method) |
118 |
|
119 |
def main(self, method=None): |
120 |
self._run(method)
|
121 |
|
122 |
|
123 |
@command(test_cmds)
|
124 |
class test_image(_test_init): |
125 |
""" test Image client"""
|
126 |
|
127 |
@errors.generic.all
|
128 |
def _run(self, method=None): |
129 |
super(self.__class__, self)._run('image', method) |
130 |
|
131 |
def main(self, method=None): |
132 |
self._run(method)
|
133 |
|
134 |
|
135 |
@command(test_cmds)
|
136 |
class test_astakos(_test_init): |
137 |
""" test Astakos client"""
|
138 |
|
139 |
@errors.generic.all
|
140 |
def _run(self, method=None): |
141 |
super(self.__class__, self)._run('astakos', method) |
142 |
|
143 |
def main(self, method=None): |
144 |
self._run(method)
|
145 |
|
146 |
|
147 |
@command(test_cmds)
|
148 |
class test_prints(_test_init): |
149 |
""" user-test print methods for lists and dicts"""
|
150 |
|
151 |
d1 = {'key0a': 'val0a', 'key0b': 'val0b', 'key0c': 'val0c'} |
152 |
|
153 |
l1 = [1, 'string', '3', 'many (2 or 3) numbers and strings combined', 5] |
154 |
|
155 |
d2 = {'id': 'val0a', 'key0b': d1, 'title': l1} |
156 |
|
157 |
l2 = [d2, l1, d1] |
158 |
|
159 |
d3 = {'dict 1': d1, 'dict 2': d2, 'list2': l2, |
160 |
'long key of size 75 characters is used to' +\
|
161 |
' check the effects on total result': l1}
|
162 |
|
163 |
@errors.generic.all
|
164 |
def _run(self): |
165 |
from kamaki.cli.utils import print_dict, print_list, print_items |
166 |
print('Test simple dict:\n- - -')
|
167 |
print_dict(self.d1)
|
168 |
print('- - -\n')
|
169 |
print('\nTest simple list:\n- - -')
|
170 |
print_list(self.l1)
|
171 |
print('- - -\n')
|
172 |
print('\nTest 2-level dict:\n- - -')
|
173 |
print_dict(self.d2)
|
174 |
print('- - -\n')
|
175 |
print('\nTest non-trivial list:\n- - -')
|
176 |
print_list(self.l2)
|
177 |
print('- - -')
|
178 |
print('\nTest extreme dict:\n- - -')
|
179 |
print_dict(self.d3)
|
180 |
print('- - -\n')
|
181 |
print('Test simple enumerated dict:\n- - -')
|
182 |
print_dict(self.d1, with_enumeration=True) |
183 |
print('- - -\n')
|
184 |
print('\nTest simple enumerated list:\n- - -')
|
185 |
print_list(self.l1, with_enumeration=True) |
186 |
print('- - -\n')
|
187 |
print('Test non-trivial deep-enumerated dict:\n- - -')
|
188 |
print_dict(self.d2, with_enumeration=True, recursive_enumeration=True) |
189 |
print('- - -\n')
|
190 |
print('\nTest non-trivial enumerated list:\n- - -')
|
191 |
print_list(self.l2, with_enumeration=True) |
192 |
print('- - -\n')
|
193 |
print('\nTest print_items with id:\n- - -')
|
194 |
print_items([{'id': '42', 'title': 'lalakis 1', 'content': self.d1}, |
195 |
{'id': '142', 'title': 'lalakis 2', 'content': self.d2}]) |
196 |
print('- - -')
|
197 |
print('\nTest print_items with id and enumeration:\n- - -')
|
198 |
print_items([{'id': '42', 'title': 'lalakis 1', 'content': self.d1}, |
199 |
{'id': '142', 'title': 'lalakis 2', 'content': self.d2}], |
200 |
with_enumeration=True)
|
201 |
print('- - -')
|
202 |
print('\nTest print_items with id, title and redundancy:\n- - -')
|
203 |
print_items([{'id': '42', 'title': 'lalakis 1', 'content': self.d1}, |
204 |
{'id': '142', 'title': 'lalakis 2', 'content': self.d2}], |
205 |
title=('id', 'title'), |
206 |
with_redundancy=True)
|
207 |
print('- - -')
|
208 |
print('\nTest print_items with lists- - -')
|
209 |
print_items([['i00', 'i01', 'i02'], [self.l2, 'i11', self.d1], 3]) |
210 |
print('- - -')
|
211 |
|
212 |
def main(self): |
213 |
self._run()
|