root / kamaki / cli / commands / test_cli.py @ d1f78278
History | View | Annotate | Download (6.6 kB)
1 | 33e3437a | Stavros Sachtouris | # Copyright 2012-2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 33e3437a | Stavros Sachtouris | #
|
3 | 33e3437a | Stavros Sachtouris | # Redistribution and use in source and binary forms, with or
|
4 | 33e3437a | Stavros Sachtouris | # without modification, are permitted provided that the following
|
5 | 33e3437a | Stavros Sachtouris | # conditions are met:
|
6 | 33e3437a | Stavros Sachtouris | #
|
7 | 33e3437a | Stavros Sachtouris | # 1. Redistributions of source code must retain the above
|
8 | 33e3437a | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
9 | 33e3437a | Stavros Sachtouris | # disclaimer.
|
10 | 33e3437a | Stavros Sachtouris | #
|
11 | 33e3437a | Stavros Sachtouris | # 2. Redistributions in binary form must reproduce the above
|
12 | 33e3437a | Stavros Sachtouris | # copyright notice, this list of conditions and the following
|
13 | 33e3437a | Stavros Sachtouris | # disclaimer in the documentation and/or other materials
|
14 | 33e3437a | Stavros Sachtouris | # provided with the distribution.
|
15 | 33e3437a | Stavros Sachtouris | #
|
16 | 33e3437a | Stavros Sachtouris | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 33e3437a | Stavros Sachtouris | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 33e3437a | Stavros Sachtouris | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 33e3437a | Stavros Sachtouris | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 33e3437a | Stavros Sachtouris | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 33e3437a | Stavros Sachtouris | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 33e3437a | Stavros Sachtouris | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 33e3437a | Stavros Sachtouris | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 33e3437a | Stavros Sachtouris | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 33e3437a | Stavros Sachtouris | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 33e3437a | Stavros Sachtouris | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 33e3437a | Stavros Sachtouris | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 33e3437a | Stavros Sachtouris | #
|
29 | 33e3437a | Stavros Sachtouris | # The views and conclusions contained in the software and
|
30 | 33e3437a | Stavros Sachtouris | # documentation are those of the authors and should not be
|
31 | 33e3437a | Stavros Sachtouris | # interpreted as representing official policies, either expressed
|
32 | 33e3437a | Stavros Sachtouris | # or implied, of GRNET S.A.command
|
33 | 33e3437a | Stavros Sachtouris | |
34 | 1f0370c9 | Stavros Sachtouris | from kamaki.cli.commands import errors |
35 | e0f40c94 | Stavros Sachtouris | from kamaki.cli import command |
36 | 03fd7ddb | Stavros Sachtouris | from kamaki.cli.commands import _command_init |
37 | af6de846 | Stavros Sachtouris | from kamaki.cli.command_tree import CommandTree |
38 | 75c3fc42 | Stavros Sachtouris | from kamaki.clients import tests |
39 | 1f0370c9 | Stavros Sachtouris | from kamaki.cli.errors import raiseCLIError |
40 | 234954d1 | Stavros Sachtouris | |
41 | 75c3fc42 | Stavros Sachtouris | test_cmds = CommandTree('test', 'Unitest clients') |
42 | 75c3fc42 | Stavros Sachtouris | _commands = [test_cmds] |
43 | 234954d1 | Stavros Sachtouris | |
44 | af6de846 | Stavros Sachtouris | |
45 | af6de846 | Stavros Sachtouris | class _test_init(_command_init): |
46 | 0d249b3e | Stavros Sachtouris | |
47 | 75c3fc42 | Stavros Sachtouris | def main(self, client, method=None): |
48 | 75c3fc42 | Stavros Sachtouris | if method:
|
49 | d1f78278 | Stavros Sachtouris | tests.main([client, method], config=self.config)
|
50 | 75c3fc42 | Stavros Sachtouris | else:
|
51 | d1f78278 | Stavros Sachtouris | tests.main([client], config=self.config)
|
52 | 234954d1 | Stavros Sachtouris | |
53 | af6de846 | Stavros Sachtouris | |
54 | 75c3fc42 | Stavros Sachtouris | @command(test_cmds)
|
55 | 3667e969 | Stavros Sachtouris | class test_error(_test_init): |
56 | 3667e969 | Stavros Sachtouris | """Create an error message with optional message"""
|
57 | 3667e969 | Stavros Sachtouris | |
58 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
59 | 1f0370c9 | Stavros Sachtouris | def _run(self, errmsg='', importance=0, index=0): |
60 | 3667e969 | Stavros Sachtouris | l = [1, 2] |
61 | 3667e969 | Stavros Sachtouris | try:
|
62 | 3667e969 | Stavros Sachtouris | l[int(index)]
|
63 | 3667e969 | Stavros Sachtouris | except Exception as err: |
64 | 3667e969 | Stavros Sachtouris | raiseCLIError(err, errmsg, importance) |
65 | 3667e969 | Stavros Sachtouris | raiseCLIError(None, errmsg, importance)
|
66 | 3667e969 | Stavros Sachtouris | |
67 | 1f0370c9 | Stavros Sachtouris | def main(self, errmsg='', importance=0, index=0): |
68 | 1f0370c9 | Stavros Sachtouris | self._run(errmsg, importance, index)
|
69 | 1f0370c9 | Stavros Sachtouris | |
70 | 3667e969 | Stavros Sachtouris | |
71 | 3667e969 | Stavros Sachtouris | @command(test_cmds)
|
72 | e0f40c94 | Stavros Sachtouris | class test_args(_test_init): |
73 | e0f40c94 | Stavros Sachtouris | """Test how arguments are treated by kamaki"""
|
74 | e0f40c94 | Stavros Sachtouris | |
75 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
76 | 1f0370c9 | Stavros Sachtouris | def _run(self, *args): |
77 | e0f40c94 | Stavros Sachtouris | print(args) |
78 | e0f40c94 | Stavros Sachtouris | |
79 | 1f0370c9 | Stavros Sachtouris | def main(self, *args): |
80 | 1f0370c9 | Stavros Sachtouris | self._run(args)
|
81 | 1f0370c9 | Stavros Sachtouris | |
82 | e0f40c94 | Stavros Sachtouris | |
83 | e0f40c94 | Stavros Sachtouris | @command(test_cmds)
|
84 | 75c3fc42 | Stavros Sachtouris | class test_all(_test_init): |
85 | 75c3fc42 | Stavros Sachtouris | """test all clients"""
|
86 | 78496d42 | Stavros Sachtouris | |
87 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
88 | 1f0370c9 | Stavros Sachtouris | def _run(self): |
89 | 75c3fc42 | Stavros Sachtouris | for client in ('pithos', 'cyclades', 'image', 'astakos'): |
90 | 75c3fc42 | Stavros Sachtouris | super(self.__class__, self).main(client) |
91 | 78496d42 | Stavros Sachtouris | |
92 | 1f0370c9 | Stavros Sachtouris | def main(self): |
93 | 1f0370c9 | Stavros Sachtouris | self._run()
|
94 | 1f0370c9 | Stavros Sachtouris | |
95 | 78496d42 | Stavros Sachtouris | |
96 | 75c3fc42 | Stavros Sachtouris | @command(test_cmds)
|
97 | 75c3fc42 | Stavros Sachtouris | class test_pithos(_test_init): |
98 | 75c3fc42 | Stavros Sachtouris | """ test Pithos client"""
|
99 | 78496d42 | Stavros Sachtouris | |
100 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
101 | 1f0370c9 | Stavros Sachtouris | def _run(self, method=None): |
102 | 75c3fc42 | Stavros Sachtouris | super(self.__class__, self).main('pithos', method) |
103 | 78496d42 | Stavros Sachtouris | |
104 | 1f0370c9 | Stavros Sachtouris | def main(self, method=None): |
105 | 1f0370c9 | Stavros Sachtouris | self._run(method)
|
106 | 1f0370c9 | Stavros Sachtouris | |
107 | 78496d42 | Stavros Sachtouris | |
108 | d486baec | Stavros Sachtouris | @command(test_cmds)
|
109 | 75c3fc42 | Stavros Sachtouris | class test_cyclades(_test_init): |
110 | 75c3fc42 | Stavros Sachtouris | """ test Cyclades client"""
|
111 | c59aef27 | Stavros Sachtouris | |
112 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
113 | 1f0370c9 | Stavros Sachtouris | def _run(self, method=None): |
114 | 75c3fc42 | Stavros Sachtouris | super(self.__class__, self).main('cyclades', method) |
115 | c59aef27 | Stavros Sachtouris | |
116 | 1f0370c9 | Stavros Sachtouris | def main(self, method=None): |
117 | 1f0370c9 | Stavros Sachtouris | self._run(method)
|
118 | 1f0370c9 | Stavros Sachtouris | |
119 | 78496d42 | Stavros Sachtouris | |
120 | d486baec | Stavros Sachtouris | @command(test_cmds)
|
121 | 75c3fc42 | Stavros Sachtouris | class test_image(_test_init): |
122 | 75c3fc42 | Stavros Sachtouris | """ test Image client"""
|
123 | 0d249b3e | Stavros Sachtouris | |
124 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
125 | 1f0370c9 | Stavros Sachtouris | def _run(self, method=None): |
126 | 75c3fc42 | Stavros Sachtouris | super(self.__class__, self).main('image', method) |
127 | 33e3437a | Stavros Sachtouris | |
128 | 1f0370c9 | Stavros Sachtouris | def main(self, method=None): |
129 | 1f0370c9 | Stavros Sachtouris | self._run(method)
|
130 | 1f0370c9 | Stavros Sachtouris | |
131 | 78496d42 | Stavros Sachtouris | |
132 | d486baec | Stavros Sachtouris | @command(test_cmds)
|
133 | 75c3fc42 | Stavros Sachtouris | class test_astakos(_test_init): |
134 | 75c3fc42 | Stavros Sachtouris | """ test Astakos client"""
|
135 | 33e3437a | Stavros Sachtouris | |
136 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
137 | 1f0370c9 | Stavros Sachtouris | def _run(self, method=None): |
138 | 75c3fc42 | Stavros Sachtouris | super(self.__class__, self).main('astakos', method) |
139 | b9b7bd83 | Stavros Sachtouris | |
140 | 1f0370c9 | Stavros Sachtouris | def main(self, method=None): |
141 | 1f0370c9 | Stavros Sachtouris | self._run(method)
|
142 | 1f0370c9 | Stavros Sachtouris | |
143 | b9b7bd83 | Stavros Sachtouris | |
144 | b9b7bd83 | Stavros Sachtouris | @command(test_cmds)
|
145 | b9b7bd83 | Stavros Sachtouris | class test_prints(_test_init): |
146 | b9b7bd83 | Stavros Sachtouris | """ user-test print methods for lists and dicts"""
|
147 | b9b7bd83 | Stavros Sachtouris | |
148 | b9b7bd83 | Stavros Sachtouris | d1 = {'key0a': 'val0a', 'key0b': 'val0b', 'key0c': 'val0c'} |
149 | b9b7bd83 | Stavros Sachtouris | |
150 | b9b7bd83 | Stavros Sachtouris | l1 = [1, 'string', '3', 'many (2 or 3) numbers and strings combined', 5] |
151 | b9b7bd83 | Stavros Sachtouris | |
152 | a494a741 | Stavros Sachtouris | d2 = {'id': 'val0a', 'key0b': d1, 'title': l1} |
153 | b9b7bd83 | Stavros Sachtouris | |
154 | b9b7bd83 | Stavros Sachtouris | l2 = [d2, l1, d1] |
155 | b9b7bd83 | Stavros Sachtouris | |
156 | f91bc6b1 | Stavros Sachtouris | d3 = {'dict 1': d1, 'dict 2': d2, 'list2': l2, |
157 | f91bc6b1 | Stavros Sachtouris | 'long key of size 75 characters is used to' +\
|
158 | f91bc6b1 | Stavros Sachtouris | ' check the effects on total result': l1}
|
159 | f91bc6b1 | Stavros Sachtouris | |
160 | 1f0370c9 | Stavros Sachtouris | @errors.generic.all
|
161 | 1f0370c9 | Stavros Sachtouris | def _run(self): |
162 | a494a741 | Stavros Sachtouris | from kamaki.cli.utils import print_dict, print_list, print_items |
163 | f91bc6b1 | Stavros Sachtouris | print('Test simple dict:\n- - -')
|
164 | b9b7bd83 | Stavros Sachtouris | print_dict(self.d1)
|
165 | f91bc6b1 | Stavros Sachtouris | print('- - -\n')
|
166 | f91bc6b1 | Stavros Sachtouris | print('\nTest simple list:\n- - -')
|
167 | b9b7bd83 | Stavros Sachtouris | print_list(self.l1)
|
168 | f91bc6b1 | Stavros Sachtouris | print('- - -\n')
|
169 | f91bc6b1 | Stavros Sachtouris | print('\nTest 2-level dict:\n- - -')
|
170 | f91bc6b1 | Stavros Sachtouris | print_dict(self.d2)
|
171 | f91bc6b1 | Stavros Sachtouris | print('- - -\n')
|
172 | f91bc6b1 | Stavros Sachtouris | print('\nTest non-trivial list:\n- - -')
|
173 | f91bc6b1 | Stavros Sachtouris | print_list(self.l2)
|
174 | f91bc6b1 | Stavros Sachtouris | print('- - -')
|
175 | f91bc6b1 | Stavros Sachtouris | print('\nTest extreme dict:\n- - -')
|
176 | f91bc6b1 | Stavros Sachtouris | print_dict(self.d3)
|
177 | f91bc6b1 | Stavros Sachtouris | print('- - -\n')
|
178 | f8681ec8 | Stavros Sachtouris | print('Test simple enumerated dict:\n- - -')
|
179 | f8681ec8 | Stavros Sachtouris | print_dict(self.d1, with_enumeration=True) |
180 | f8681ec8 | Stavros Sachtouris | print('- - -\n')
|
181 | d4abd11c | Stavros Sachtouris | print('\nTest simple enumerated list:\n- - -')
|
182 | f8681ec8 | Stavros Sachtouris | print_list(self.l1, with_enumeration=True) |
183 | f8681ec8 | Stavros Sachtouris | print('- - -\n')
|
184 | f8681ec8 | Stavros Sachtouris | print('Test non-trivial deep-enumerated dict:\n- - -')
|
185 | f8681ec8 | Stavros Sachtouris | print_dict(self.d2, with_enumeration=True, recursive_enumeration=True) |
186 | d4abd11c | Stavros Sachtouris | print('- - -\n')
|
187 | d4abd11c | Stavros Sachtouris | print('\nTest non-trivial enumerated list:\n- - -')
|
188 | f8681ec8 | Stavros Sachtouris | print_list(self.l2, with_enumeration=True) |
189 | a494a741 | Stavros Sachtouris | print('- - -\n')
|
190 | a494a741 | Stavros Sachtouris | print('\nTest print_items with id:\n- - -')
|
191 | a494a741 | Stavros Sachtouris | print_items([{'id': '42', 'title': 'lalakis 1', 'content': self.d1}, |
192 | a494a741 | Stavros Sachtouris | {'id': '142', 'title': 'lalakis 2', 'content': self.d2}]) |
193 | a494a741 | Stavros Sachtouris | print('- - -')
|
194 | a494a741 | Stavros Sachtouris | print('\nTest print_items with id and enumeration:\n- - -')
|
195 | a494a741 | Stavros Sachtouris | print_items([{'id': '42', 'title': 'lalakis 1', 'content': self.d1}, |
196 | a494a741 | Stavros Sachtouris | {'id': '142', 'title': 'lalakis 2', 'content': self.d2}], |
197 | a494a741 | Stavros Sachtouris | with_enumeration=True)
|
198 | a494a741 | Stavros Sachtouris | print('- - -')
|
199 | a494a741 | Stavros Sachtouris | print('\nTest print_items with id, title and redundancy:\n- - -')
|
200 | a494a741 | Stavros Sachtouris | print_items([{'id': '42', 'title': 'lalakis 1', 'content': self.d1}, |
201 | a494a741 | Stavros Sachtouris | {'id': '142', 'title': 'lalakis 2', 'content': self.d2}], |
202 | a494a741 | Stavros Sachtouris | title=('id', 'title'), |
203 | a494a741 | Stavros Sachtouris | with_redundancy=True)
|
204 | a494a741 | Stavros Sachtouris | print('- - -')
|
205 | a494a741 | Stavros Sachtouris | print('\nTest print_items with lists- - -')
|
206 | a494a741 | Stavros Sachtouris | print_items([['i00', 'i01', 'i02'], [self.l2, 'i11', self.d1], 3]) |
207 | d4abd11c | Stavros Sachtouris | print('- - -')
|
208 | 1f0370c9 | Stavros Sachtouris | |
209 | 1f0370c9 | Stavros Sachtouris | def main(self): |
210 | 1f0370c9 | Stavros Sachtouris | self._run() |