Permalink
Browse files

Fixed MongoMock to use DuplicateKeyError.

  • Loading branch information...
1 parent 05144db commit b32bbbebca98573d840af0fcbbeab8691aee4035 Josh Finnie committed Nov 29, 2012
Showing with 4 additions and 6 deletions.
  1. +3 −5 lumin/node.py
  2. +1 −1 lumin/tests/test_node.py
View
@@ -82,16 +82,14 @@ def insert(self, doc, title_or_id, increment=True, seperator='-'):
_id = doc['_id']
while True:
try:
- # oid = self._collection.insert(doc, safe=True) ## Mongomock does not support `safe=True`
- oid = self._collection.insert(doc)
+ oid = self._collection.insert(doc, safe=True)
break
- except AssertionError:
+ except DuplicateKeyError:
suffix += 1
_id_suffixed = seperator.join([_id, str(suffix)])
doc['_id'] = _id_suffixed
else:
- # oid = self._collection.insert(doc, safe=True) ## Mongomock does not support `safe=True`
- oid = self._collection.insert(doc)
+ oid = self._collection.insert(doc, safe=True)
return oid
@@ -111,7 +111,7 @@ def test_collection_insert_duplicate_key(self):
def test_collection_insert_duplicate_key_increment_false(self):
result = self._call_fut(request=self.request)
result.insert({u'name': u'Foo'}, u'first user', increment=False)
- self.assertRaises(AssertionError, result.insert, {u'name': u'Bar'}, u'first user', increment=False)
+ self.assertRaises(DuplicateKeyError, result.insert, {u'name': u'Bar'}, u'first user', increment=False)
# TODO - Need to work out MongoMock's handeling of safe...
def test_collection_delete(self):

0 comments on commit b32bbbe

Please sign in to comment.