1 # Copyright 2012-2013 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
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.
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.
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
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
39 test_cmds = CommandTree('test', 'Unitest clients')
40 _commands = [test_cmds]
43 #print('Command Terms: ', get_cmd_terms())
46 class _test_init(_command_init):
48 def main(self, client, method=None):
49 tests.cnf = self.config
51 tests.main([client, method])
57 class test_error(_test_init):
58 """Create an error message with optional message"""
60 def main(self, errmsg='', importance=0, index=0):
61 from kamaki.cli.errors import raiseCLIError
65 except Exception as err:
66 raiseCLIError(err, errmsg, importance)
67 raiseCLIError(None, errmsg, importance)
71 class test_args(_test_init):
72 """Test how arguments are treated by kamaki"""
74 def main(self, *args):
79 class test_all(_test_init):
80 """test all clients"""
83 for client in ('pithos', 'cyclades', 'image', 'astakos'):
84 super(self.__class__, self).main(client)
88 class test_pithos(_test_init):
89 """ test Pithos client"""
91 def main(self, method=None):
92 super(self.__class__, self).main('pithos', method)
96 class test_cyclades(_test_init):
97 """ test Cyclades client"""
99 def main(self, method=None):
100 super(self.__class__, self).main('cyclades', method)
104 class test_image(_test_init):
105 """ test Image client"""
107 def main(self, method=None):
108 super(self.__class__, self).main('image', method)
112 class test_astakos(_test_init):
113 """ test Astakos client"""
115 def main(self, method=None):
116 super(self.__class__, self).main('astakos', method)
120 class test_prints(_test_init):
121 """ user-test print methods for lists and dicts"""
123 d1 = {'key0a': 'val0a', 'key0b': 'val0b', 'key0c': 'val0c'}
125 l1 = [1, 'string', '3', 'many (2 or 3) numbers and strings combined', 5]
127 d2 = {'key1a': 'val0a', 'key1b': d1, 'key1c': l1}
131 d3 = {'dict 1': d1, 'dict 2': d2, 'list2': l2,
132 'long key of size 75 characters is used to' +\
133 ' check the effects on total result': l1}
136 from kamaki.cli.utils import print_dict, print_list
137 print('Test simple dict:\n- - -')
140 print('\nTest simple list:\n- - -')
143 print('\nTest 2-level dict:\n- - -')
146 print('\nTest non-trivial list:\n- - -')
149 print('\nTest extreme dict:\n- - -')