Commits

Andy Mikhailenko committed 495fb5b

Added method MongoBoundDictMixin.remove().

  • Participants
  • Parent commits fac1094

Comments (0)

Files changed (4)

File monk/__init__.py

 .. _pymongo: http://api.mongodb.org/python/current/
 
 """
-__version__ = '0.3.1'
+__version__ = '0.4.0'
 # remember to also update:
 #
 # * PKGBUILD

File monk/modeling.py

         else:
             return dbref.DBRef(self.collection, _id)
 
+    def remove(self, db):
+        """
+        Removes the object from given database. Usage::
+
+            item = Item.get_one(db)
+            item.remove(db)
+
+        Collection name is taken from :attr:`MongoBoundDictMixin.collection`.
+        """
+        assert self.collection
+        assert self.get_id()
+
+        db[self.collection].remove(self.get_id())
+
 
 class StructuredDictMixin(object):
     """ A dictionary with structure specification and validation.

File unittests/test_modeling.py

         assert self.collection.find().count() == 1
         assert self.collection.find({'title': u'Hello'}).count() == 1
 
+    def test_remove(self):
+        self.collection.insert({'title': u'Hello'})
+
+        entries = self.Entry.find(self.db)
+        assert entries.count() == 1
+
+        entry = entries[0]
+        entry.remove(self.db)
+
+        entries = self.Entry.find(self.db)
+        assert entries.count() == 0
+
     def test_id(self):
         entry = self.Entry(title=u'Hello')
         assert entry['_id'] is None

File unittests/test_validation.py

 
         with pytest.raises(StructureSpecificationError) as excinfo:
             validate_structure_spec({'foo': [unicode, unicode]})
-        print 'excinfo',excinfo
         assert single_elem_err_msg in str(excinfo)
 
         with pytest.raises(StructureSpecificationError) as excinfo: