Skip to content

Commit

Permalink
Make sure we can delete in a batch operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Jan 22, 2016
1 parent 551d1f4 commit 4dc096d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
35 changes: 31 additions & 4 deletions kinto_client/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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'})
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions kinto_client/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 4dc096d

Please sign in to comment.