Revision e7e7dbbd
b/kamaki/cli/commands/test_cli.py | ||
---|---|---|
46 | 46 |
|
47 | 47 |
def _run(self, client, method=None): |
48 | 48 |
if method: |
49 |
tests._main([client, method], config=self.config)
|
|
49 |
tests.main([client, method], config=self.config) |
|
50 | 50 |
else: |
51 |
tests._main([client], config=self.config)
|
|
51 |
tests.main([client], config=self.config) |
|
52 | 52 |
|
53 | 53 |
def main(self, client, method=None): |
54 | 54 |
return self._run(client, method) |
b/kamaki/clients/connection/__init__.py | ||
---|---|---|
37 | 37 |
Subclass implementation required |
38 | 38 |
""" |
39 | 39 |
|
40 |
def __init__(self, request=None, prefetched=False):
|
|
40 |
def __init__(self, request, prefetched=False): |
|
41 | 41 |
self.request = request |
42 | 42 |
self.prefetched = prefetched |
43 | 43 |
|
44 | 44 |
def _get_response(self): |
45 |
"""Wait for http response as late as possible: the first time needed"""
|
|
45 |
"""Wait for http response as late as possible""" |
|
46 | 46 |
if self.prefetched: |
47 | 47 |
return |
48 | 48 |
self = self.request.response |
... | ... | |
64 | 64 |
|
65 | 65 |
@property |
66 | 66 |
def content(self): |
67 |
"""(binary) request response content (data)""" |
|
67 |
""":returns: (binary) request response content (data)"""
|
|
68 | 68 |
self._get_response() |
69 | 69 |
return self._content |
70 | 70 |
|
b/kamaki/clients/connection/test.py | ||
---|---|---|
1 |
# Copyright 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, self.list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, self.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 unittest import TestCase, TestSuite, TextTestRunner, TestLoader |
|
35 |
from mock import Mock |
|
36 |
|
|
37 |
|
|
38 |
class HTTPResponse(TestCase): |
|
39 |
|
|
40 |
def setUp(self): |
|
41 |
from kamaki.clients.connection import HTTPResponse as HTTPR |
|
42 |
self.resp = HTTPR('Abstract class, so test with fake request (str)') |
|
43 |
|
|
44 |
def _mock_get_response(foo): |
|
45 |
def mocker(self): |
|
46 |
self.resp._get_response = Mock() |
|
47 |
foo(self) |
|
48 |
return mocker |
|
49 |
|
|
50 |
def test_release(self): |
|
51 |
self.assertRaises(NotImplementedError, self.resp.release) |
|
52 |
|
|
53 |
def test_prefetched(self): |
|
54 |
self.assertFalse(self.resp.prefetched) |
|
55 |
self.resp.prefetched = True |
|
56 |
self.assertTrue(self.resp.prefetched) |
|
57 |
|
|
58 |
@_mock_get_response |
|
59 |
def test_content(self): |
|
60 |
rsp = self.resp |
|
61 |
for cont in ('Sample Content', u'\u03c7\u03cd\u03bd\u03c9\x00'): |
|
62 |
rsp.content = cont |
|
63 |
self.assertEquals(rsp.content, cont) |
|
64 |
|
|
65 |
( |
|
66 |
test_text, |
|
67 |
test_json, |
|
68 |
test_headers, |
|
69 |
test_status, |
|
70 |
test_status_code) = 5 * (test_content,) |
|
71 |
|
|
72 |
def test_request(self): |
|
73 |
from httplib import HTTPSConnection |
|
74 |
r = self.resp.request |
|
75 |
self.assertTrue(isinstance(r, HTTPSConnection)) |
|
76 |
|
|
77 |
|
|
78 |
def main(argv): |
|
79 |
if argv: |
|
80 |
suite = TestSuite() |
|
81 |
test_method = 'test_%s' % '_'.join(argv) |
|
82 |
suite.addTest(HTTPResponse(test_method)) |
|
83 |
else: |
|
84 |
suite = TestLoader().loadTestsFromTestCase(HTTPResponse) |
|
85 |
TextTestRunner(verbosity=2).run(suite) |
|
86 |
|
|
87 |
|
|
88 |
if __name__ == '__main__': |
|
89 |
from sys import argv |
|
90 |
main(argv[1:]) |
b/kamaki/clients/tests/__init__.py | ||
---|---|---|
164 | 164 |
return parser |
165 | 165 |
|
166 | 166 |
|
167 |
def main(argv): |
|
168 |
_main(argv, config=None) |
|
169 |
|
|
170 |
|
|
171 |
def _main(argv, config=None): |
|
167 |
def main(argv, config=None): |
|
172 | 168 |
suiteFew = TestSuite() |
173 | 169 |
if len(argv) == 0 or argv[0] == 'pithos': |
174 | 170 |
from kamaki.clients.tests.pithos import Pithos |
b/kamaki/clients/tests/image.py | ||
---|---|---|
57 | 57 |
def _prepare_img(self): |
58 | 58 |
f = open(self['image', 'local_path'], 'rb') |
59 | 59 |
(token, uuid) = (self['token'], self['store', 'account']) |
60 |
print('UUID HERE: %s (%s)' % (uuid, token)) |
|
61 | 60 |
if not uuid: |
62 | 61 |
from kamaki.clients.astakos import AstakosClient |
63 | 62 |
uuid = AstakosClient(self['astakos', 'url'], token).term('uuid') |
64 |
print('UUID HERE: %s' % uuid) |
|
65 | 63 |
from kamaki.clients.pithos import PithosClient |
66 | 64 |
self.pithcli = PithosClient(self['store', 'url'], token, uuid) |
67 | 65 |
cont = 'cont_%s' % self.now |
... | ... | |
70 | 68 |
print('\t- Create container %s on Pithos server' % cont) |
71 | 69 |
self.pithcli.container_put() |
72 | 70 |
self.location = 'pithos://%s/%s/%s' % (uuid, cont, self.obj) |
73 |
print('\t- Upload an image at %s...' % self.location) |
|
71 |
print('\t- Upload an image at %s...\n' % self.location)
|
|
74 | 72 |
self.pithcli.upload_object(self.obj, f) |
75 | 73 |
print('\t- ok') |
76 | 74 |
f.close() |
b/setup.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
optional = ['ansicolors', |
44 | 44 |
'progress>=1.0.2'] |
45 |
requires = ['objpool'] |
|
45 |
requires = ['objpool', 'mock']
|
|
46 | 46 |
|
47 | 47 |
if version_info < (2, 7): |
48 | 48 |
requires.append('argparse') |
Also available in: Unified diff