From: Stavros Sachtouris Date: Tue, 19 Mar 2013 13:46:29 +0000 (+0200) Subject: Unittest PithosRest.container_post X-Git-Tag: 0.9rc1~82^2~23 X-Git-Url: https://code.grnet.gr/git/kamaki/commitdiff_plain/7702c4298cf16a21c12e330c64e292b2ba6bb315 Unittest PithosRest.container_post --- diff --git a/kamaki/clients/pithos/rest_api.py b/kamaki/clients/pithos/rest_api.py index 0670c52..9bdffaa 100644 --- a/kamaki/clients/pithos/rest_api.py +++ b/kamaki/clients/pithos/rest_api.py @@ -348,20 +348,20 @@ class PithosRestClient(StorageClient): :param content_length: (string) set a custrom content length - :param transfer_encoding: (string) set a custrom transfer encoding + :param transfer_encoding: (string) set a custom transfer encoding :returns: ConnectionResponse """ self._assert_container() - self.set_param('format', format, iff=format) self.set_param('update', iff=update) + self.set_param('format', format, iff=format) + self.set_header('X-Container-Policy-Quota', quota) + self.set_header('X-Container-Policy-Versioning', versioning) if metadata: for metaname, metaval in metadata.items(): self.set_header('X-Container-Meta-' + metaname, metaval) - self.set_header('X-Container-Policy-Quota', quota) - self.set_header('X-Container-Policy-Versioning', versioning) self.set_header('Content-Type', content_type) self.set_header('Content-Length', content_length) self.set_header('Transfer-Encoding', transfer_encoding) diff --git a/kamaki/clients/pithos/test.py b/kamaki/clients/pithos/test.py index 37d7bf5..06d807e 100644 --- a/kamaki/clients/pithos/test.py +++ b/kamaki/clients/pithos/test.py @@ -352,6 +352,45 @@ class PithosRest(TestCase): success=kwargs.pop('success', (201, 202)), **kwargs)) + @patch('%s.set_param' % rest_pkg) + @patch('%s.set_header' % rest_pkg) + @patch('%s.post' % rest_pkg, return_value=FR()) + def test_container_post(self, post, SH, SP): + for pm in product( + (True, False), + ('json', 'some-format'), + (None, 'quota'), + (None, 'v3r51on1ng'), + (dict(), dict(k1='v2'), dict(k2='v2', k3='v3')), + (None, 'content-type'), + (None, 42), + (None, 'transfer-encoding'), + ((), ('someval',)), + (dict(), dict(success=400), dict(k='v', v='k'))): + args, kwargs = pm[-2:] + pm = pm[:-2] + self.client.container_post(*(pm + args), **kwargs) + upd, frmt = pm[:2] + self.assertEqual(SP.mock_calls[-2:], [ + call('update', iff=upd), + call('format', frmt, iff=frmt)]) + qta, vrs, metas, ctype, clen, trenc = pm[2:] + prfx = 'X-Container-Meta-' + exp = [ + call('X-Container-Policy-Quota', qta), + call('X-Container-Policy-Versioning', vrs)] + [ + call('%s%s' % (prfx, k), v) for k, v in metas.items()] + [ + call('Content-Type', ctype), + call('Content-Length', clen), + call('Transfer-Encoding', trenc)] + self.assertEqual(SH.mock_calls[- len(exp):], exp) + ims, ius = pm[-2:] + self.assertEqual(post.mock_calls[-1], call( + '/%s/%s' % (self.client.account, self.client.container), + *args, + success=kwargs.pop('success', 202), + **kwargs)) + class Pithos(TestCase):