Revision 6cd86652 kamaki/clients/pithos/test.py
b/kamaki/clients/pithos/test.py | ||
---|---|---|
36 | 36 |
from tempfile import NamedTemporaryFile |
37 | 37 |
from os import urandom |
38 | 38 |
from itertools import product |
39 |
from random import randint |
|
39 | 40 |
|
40 | 41 |
try: |
41 | 42 |
from collections import OrderedDict |
... | ... | |
482 | 483 |
success=kwargs.pop('success', 200), |
483 | 484 |
**kwargs)) |
484 | 485 |
|
486 |
@patch('%s.set_param' % rest_pkg) |
|
487 |
@patch('%s.set_header' % rest_pkg) |
|
488 |
@patch('%s.put' % rest_pkg, return_value=FR()) |
|
489 |
def test_object_put(self, put, SH, SP): |
|
490 |
for pm in product( |
|
491 |
('json', 'f0rm47'), |
|
492 |
(False, True), |
|
493 |
(None, 'delim',), |
|
494 |
(dict(), dict(read=['u1', 'g2'], write=['u1'])), |
|
495 |
(False, True), |
|
496 |
(dict(), dict(k2='v2', k3='v3')), |
|
497 |
((), ('someval',)), |
|
498 |
(dict(), dict(success=400), dict(k='v', v='k'))): |
|
499 |
args, kwargs = pm[-2:] |
|
500 |
pm = pm[:-2] |
|
501 |
terms = [None] * 13 |
|
502 |
for i in range(len(terms)): |
|
503 |
if randint(0, 2): |
|
504 |
terms[i] = 'val_%s' % randint(13, 1024) |
|
505 |
self.client.object_put( |
|
506 |
obj, |
|
507 |
*(pm[:3] + tuple(terms) + pm[3:] + args), |
|
508 |
**kwargs) |
|
509 |
format, hashmap, delimiter = pm[:3] |
|
510 |
self.assertEqual(SP.mock_calls[-3:], [ |
|
511 |
call('format', format, iff=format), |
|
512 |
call('hashmap', hashmap, iff=hashmap), |
|
513 |
call('delimiter', delimiter, iff=delimiter)]) |
|
514 |
( |
|
515 |
im, inm, etag, clen, ctype, trenc, |
|
516 |
cp, mv, srcacc, srcvrs, conenc, condis, mnf) = terms |
|
517 |
perms, public, metas = pm[3:] |
|
518 |
exp = [ |
|
519 |
call('If-Match', im), |
|
520 |
call('If-None-Match', inm), |
|
521 |
call('ETag', etag), |
|
522 |
call('Content-Length', clen), |
|
523 |
call('Content-Type', ctype), |
|
524 |
call('Transfer-Encoding', trenc), |
|
525 |
call('X-Copy-From', cp), |
|
526 |
call('X-Move-From', mv), |
|
527 |
call('X-Source-Account', srcacc), |
|
528 |
call('X-Source-Version', srcvrs), |
|
529 |
call('Content-Encoding', conenc), |
|
530 |
call('Content-Disposition', condis), |
|
531 |
call('X-Object-Manifest', mnf)] |
|
532 |
if perms: |
|
533 |
perm_str = '' |
|
534 |
for ptype, pval in perms.items(): |
|
535 |
if pval: |
|
536 |
perm_str += ';' if perm_str else '' |
|
537 |
perm_str += '%s=%s' % (ptype, ','.join(pval)) |
|
538 |
exp += [call('X-Object-Sharing', perm_str)] |
|
539 |
exp += [call('X-Object-Public', public)] |
|
540 |
for k, v in metas.items(): |
|
541 |
exp += [call('X-Object-Meta-%s' % k, v)] |
|
542 |
self.assertEqual(SH.mock_calls[- len(exp):], exp) |
|
543 |
acc, cont = self.client.account, self.client.container |
|
544 |
self.assertEqual(put.mock_calls[-1], call( |
|
545 |
'/%s/%s/%s' % (acc, cont, obj), |
|
546 |
*args, |
|
547 |
success=kwargs.pop('success', 201), |
|
548 |
**kwargs)) |
|
549 |
|
|
485 | 550 |
|
486 | 551 |
class Pithos(TestCase): |
487 | 552 |
|
Also available in: Unified diff