Skip to content

Commit

Permalink
fixup! fixup! internally switch from ensure_index to create_index
Browse files Browse the repository at this point in the history
  • Loading branch information
dill0wn committed Jun 28, 2024
1 parent 215ae5c commit af69d2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions ming/tests/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ class __mongometa__:
self.MyDoc = MyDoc

def test_ensure_indexes(self):
# make sure the manager constructor calls ensure_index with the right stuff
# make sure the manager constructor calls create_index with the right stuff
self.MyDoc.m
collection = self.MockSession.db[self.MyDoc.m.collection_name]
ensure_index = collection.ensure_index
args = ensure_index.call_args_list
create_index = collection.create_index
args = create_index.call_args_list
for a in args:
print(a)
indexes = [
Expand All @@ -182,8 +182,8 @@ def test_ensure_indexes(self):
def test_ensure_indexes_custom_options(self):
self.MyDoc.m
collection = self.MockSession.db[self.MyDoc.m.collection_name]
ensure_index = collection.ensure_index
args = ensure_index.call_args_list
create_index = collection.create_index
args = create_index.call_args_list

custom_named_index = None
for index in self.MyDoc.m.indexes:
Expand All @@ -200,29 +200,29 @@ def test_ensure_indexes_custom_options(self):
def test_ensure_indexes_slave(self):
# on a slave, an error will be thrown, but it should be swallowed
collection = self.MockSession.db[self.MyDoc.__mongometa__.name]
ensure_index = collection.ensure_index
ensure_index.side_effect = AutoReconnect('not master')
create_index = collection.create_index
create_index.side_effect = AutoReconnect('not master')
self.MyDoc.m
assert ensure_index.called
assert create_index.called

# don't keep trying after it failed once
self.MyDoc.m
assert ensure_index.call_count == 1, ensure_index.call_args_list
assert create_index.call_count == 1, create_index.call_args_list

def test_auto_ensure_indexes_option(self):
ensure_index = self.MockSession.db[self.MyDoc.__mongometa__.name].ensure_index
create_index = self.MockSession.db[self.MyDoc.__mongometa__.name].create_index
self.MockSession.bind.bind._auto_ensure_indexes = False
self.MyDoc.m
assert not ensure_index.called
assert not create_index.called

def test_ensure_indexes_other_error(self):
# same as above, but no swallowing
collection = self.MockSession.db[self.MyDoc.__mongometa__.name]
ensure_index = collection.ensure_index
ensure_index.side_effect = AutoReconnect('blah blah')
create_index = collection.create_index
create_index.side_effect = AutoReconnect('blah blah')

self.assertRaises(AutoReconnect, lambda: self.MyDoc.m)
assert ensure_index.called
assert create_index.called

def test_index_inheritance_child_none(self):
class MyChild(self.MyDoc):
Expand Down
18 changes: 9 additions & 9 deletions ming/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ def setUp(self):
Index('test2'),
Index('test1', 'test2', direction=pymongo.DESCENDING))

@mock.patch('ming.session.Session.ensure_index')
def test_ensure_indexes(self, ensure_index):
# make sure the manager constructor calls ensure_index with the right
@mock.patch('ming.session.Session.create_index')
def test_ensure_indexes(self, create_index):
# make sure the manager constructor calls create_index with the right
# stuff
self.MyDoc.m
collection = self.MockSession.db[self.MyDoc.m.collection_name]
ensure_index = collection.ensure_index
args = ensure_index.call_args_list
create_index = collection.create_index
args = create_index.call_args_list
indexes = [
( ([ ('test1', pymongo.DESCENDING), ('test2', pymongo.DESCENDING) ],),
dict(unique=False, sparse=False, background=True) ),
Expand All @@ -117,13 +117,13 @@ def test_ensure_indexes(self, ensure_index):
self.assertTrue(i in args, args)


@mock.patch('ming.session.Session.ensure_index')
def test_ensure_indexes_slave(self, ensure_index):
@mock.patch('ming.session.Session.create_index')
def test_ensure_indexes_slave(self, create_index):
# on a slave, an error will be thrown, but it should be swallowed
self.MyDoc.m
collection = self.MockSession.db[self.MyDoc.m.collection_name]
ensure_index = collection.ensure_index
assert ensure_index.called
create_index = collection.create_index
assert create_index.called

def test_index_inheritance_child_none(self):
MyChild = collection(self.MyDoc, collection_name='my_child')
Expand Down

0 comments on commit af69d2e

Please sign in to comment.