diff --git a/kinto_client/tests/test_client.py b/kinto_client/tests/test_client.py index 1135b16..e878ee0 100644 --- a/kinto_client/tests/test_client.py +++ b/kinto_client/tests/test_client.py @@ -1,6 +1,6 @@ import mock from six import text_type -from .support import unittest, mock_response, build_response +from .support import unittest, mock_response, build_response, mock_batch from kinto_client import (KintoException, BucketNotFound, Client, DO_NOT_OVERWRITE) @@ -13,9 +13,7 @@ def setUp(self): mock_response(self.session) def test_context_manager_works_as_expected(self): - settings = {"batch_max_requests": 25} - self.session.request.side_effect = [({"settings": settings}, []), - ({"responses": []}, [])] + mock_batch(self.session) with self.client.batch(bucket='mozilla', collection='test') as batch: batch.create_record(id=1234, data={'foo': 'bar'}) @@ -34,6 +32,35 @@ def test_context_manager_works_as_expected(self): 'method': 'PUT', 'headers': {'If-None-Match': '*'}}]}) + def test_context_manager_handle_delete(self): + mock_batch(self.session) + + with self.client.batch(bucket='mozilla', collection='test') as batch: + batch.delete_bucket() + batch.delete_collection() + batch.delete_record(5678) + + self.session.request.assert_called_with( + 'POST', + '/batch', + payload={'requests': [ + { + 'body': {}, + 'path': '/buckets/mozilla', + 'method': 'DELETE' + }, + { + 'body': {}, + 'path': '/buckets/mozilla/collections/test', + 'method': 'DELETE' + }, + { + 'body': {}, + 'path': '/buckets/mozilla/collections/test/records/5678', + 'method': 'DELETE' + } + ]}) + def test_batch_raises_exception(self): # Make the next call to sess.request raise a 403. exception = KintoException() diff --git a/kinto_client/tests/test_importer.py b/kinto_client/tests/test_importer.py index bed3853..2778521 100644 --- a/kinto_client/tests/test_importer.py +++ b/kinto_client/tests/test_importer.py @@ -8,7 +8,7 @@ from kinto_client.exceptions import KintoException from kinto_client.importer import KintoImporter -from .support import unittest, mock_batch +from .support import unittest HERE = os.path.dirname(__file__) logger = logging.getLogger() @@ -29,7 +29,7 @@ def assert_option_strings(self, parser, *option_strings_list): assert any([action.option_strings == option_strings for action in parser._actions]), \ "%s not found" % option_strings - + def assert_files_nargs(self, parser, nargs='+'): for action in parser._actions: assert any([action.dest == 'files' and @@ -164,7 +164,7 @@ class DummyImporter(KintoImporter): def __init__(self): self.logger = logger - + def get_auth(self, auth): self.get_auth_called = True return ('user', 'pass')