Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
added realistic FakeCollection.remove return values
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Groszer committed Feb 2, 2013
1 parent fe305ec commit d55e812
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGES
0.2.1 (unreleased)
------------------

- ...
- added realistic FakeCollection.remove return values


0.2.0 (2012-12-16)
Expand Down Expand Up @@ -38,4 +38,3 @@ CHANGES
------------------

- First independent release from m01.mongo.testing

20 changes: 14 additions & 6 deletions src/m01/mongofake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# SON to dict converter
def dictify(data):
"""Recursive replace SON items with dict in the given data structure.
Compared to the SON.to_dict method, this method will also handle tuples
and keep them intact.
Expand All @@ -57,7 +57,7 @@ def dictify(data):
# replace nested SON items
d.append(dictify(v))
if isinstance(data, tuple):
# keep tuples intact
# keep tuples intact
d = tuple(d)
else:
d = data
Expand Down Expand Up @@ -386,7 +386,7 @@ def update(self, spec, document, upsert=False, manipulate=False, safe=None,
counter = 0
for key, doc in list(self.docs.items()):
if (counter > 0 and not multi):
break
break
for k, v in spec.items():
if k in doc and v == doc[k]:
setData = document.get('$set')
Expand All @@ -412,7 +412,6 @@ def update(self, spec, document, upsert=False, manipulate=False, safe=None,
return {u'updatedExisting': existing, u'connectionId': cid, u'ok': ok,
u'err': err, u'n': counter}


def save(self, to_save, manipulate=True, safe=None, check_keys=True,
**kwargs):
if not isinstance(to_save, types.DictType):
Expand All @@ -426,7 +425,7 @@ def save(self, to_save, manipulate=True, safe=None, check_keys=True,
check_keys=check_keys, **kwargs)
return to_save.get("_id", None)

def insert(self, doc_or_docs, manipulate=True, safe=None, check_keys=True,
def insert(self, doc_or_docs, manipulate=True, safe=None, check_keys=True,
continue_on_error=False, **kwargs):
docs = doc_or_docs
if isinstance(docs, types.DictType):
Expand Down Expand Up @@ -505,8 +504,18 @@ def remove(self, spec_or_id=None, safe=False, **kwargs):
raise TypeError("spec must be an instance of dict, not %s" %
type(spec))

response = {"serverUsed": "localhost:27017",
"n": 0,
"connectionId": 42,
"wtime": 0,
"err": None,
"ok": 1.0}

for doc in self.find(spec, fields=()):
del self.docs[unicode(doc['_id'])]
response['n'] += 1

return response

# helper methods
def _fields_list_to_dict(self, fields):
Expand Down Expand Up @@ -770,4 +779,3 @@ def disconnect(self):

# single shared connection pool instance
fakeMongoConnectionPool = FakeMongoConnectionPool()

0 comments on commit d55e812

Please sign in to comment.