[Checkins] SVN: m01.mongofake/trunk/ added realistic FakeCollection.remove return values

Adam Groszer cvs-admin at zope.org
Sat Feb 2 13:11:09 UTC 2013


Log message for revision 129120:
  added realistic FakeCollection.remove return values

Changed:
  U   m01.mongofake/trunk/CHANGES.txt
  U   m01.mongofake/trunk/src/m01/mongofake/__init__.py

-=-
Modified: m01.mongofake/trunk/CHANGES.txt
===================================================================
--- m01.mongofake/trunk/CHANGES.txt	2013-02-01 21:07:15 UTC (rev 129119)
+++ m01.mongofake/trunk/CHANGES.txt	2013-02-02 13:11:08 UTC (rev 129120)
@@ -5,7 +5,7 @@
 0.2.1 (unreleased)
 ------------------
 
-- ...
+- added realistic FakeCollection.remove return values
 
 
 0.2.0 (2012-12-16)
@@ -38,4 +38,3 @@
 ------------------
 
 - First independent release from m01.mongo.testing
-

Modified: m01.mongofake/trunk/src/m01/mongofake/__init__.py
===================================================================
--- m01.mongofake/trunk/src/m01/mongofake/__init__.py	2013-02-01 21:07:15 UTC (rev 129119)
+++ m01.mongofake/trunk/src/m01/mongofake/__init__.py	2013-02-02 13:11:08 UTC (rev 129120)
@@ -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.
 
@@ -57,7 +57,7 @@
             # replace nested SON items
             d.append(dictify(v))
         if isinstance(data, tuple):
-            # keep tuples intact 
+            # keep tuples intact
             d = tuple(d)
     else:
         d = data
@@ -386,7 +386,7 @@
         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')
@@ -412,7 +412,6 @@
         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):
@@ -426,7 +425,7 @@
                 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):
@@ -505,9 +504,19 @@
             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):
         as_dict = OrderedData()
@@ -770,4 +779,3 @@
 
 # single shared connection pool instance
 fakeMongoConnectionPool = FakeMongoConnectionPool()
-



More information about the checkins mailing list