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