Skip to content

Commit

Permalink
Add bulk_write
Browse files Browse the repository at this point in the history
  • Loading branch information
Chamayou, Amaury (London) authored and Chamayou, Amaury (London) committed Jun 19, 2017
1 parent 20e10ae commit d119881
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions arctic/store/bson_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ def find_one_and_replace(self, filter, replacement, **kwargs):
self._arctic_lib.check_quota()
return self._collection.find_one_and_replace(filter, replacement, **kwargs)

@mongo_retry
def bulk_write(self, requests, **kwargs):
"""
See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.bulk_write
Warning: this is wrapped in mongo_retry, and is therefore potentially unsafe if the write you want to execute
isn't idempotent.
"""
self._arctic_lib.check_quota()
return self._collection.bulk_write(requests, **kwargs)

@mongo_retry
def count(self, filter, **kwargs):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/store/test_bson_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ def test_find_one_and_replace():
assert collection.find_one_and_replace.call_args_list == [call(sentinel.filter, sentinel.replacement)]


def test_bulk_write():
arctic_lib = create_autospec(ArcticLibraryBinding, instance=True)
collection = create_autospec(Collection, instance=True)
arctic_lib.get_top_level_collection.return_value = collection

bsons = BSONStore(arctic_lib)
bsons.bulk_write(sentinel.requests)

assert arctic_lib.check_quota.call_count == 1
assert collection.bulk_write.call_count == 1
assert collection.bulk_write.call_args_list == [call(sentinel.requests)]


def test_delete_one():
arctic_lib = create_autospec(ArcticLibraryBinding, instance=True)
collection = create_autospec(Collection, instance=True)
Expand Down

0 comments on commit d119881

Please sign in to comment.