adding last_status method to Database instances
This commit is contained in:
parent
4aa0438f76
commit
6841005a7d
@ -267,6 +267,13 @@ class Database(object):
|
||||
self.__connection._reset()
|
||||
return error
|
||||
|
||||
def last_status(self):
|
||||
"""Get status information from the last operation.
|
||||
|
||||
Returns a SON object with status information.
|
||||
"""
|
||||
return self._command({"getlasterror": 1})
|
||||
|
||||
def previous_error(self):
|
||||
"""Get the most recent error to have occurred on this database.
|
||||
|
||||
|
||||
@ -195,6 +195,18 @@ class TestDatabase(unittest.TestCase):
|
||||
self.assertEqual(None, db.error())
|
||||
self.assertEqual(None, db.previous_error())
|
||||
|
||||
def test_last_status(self):
|
||||
db = self.connection.pymongo_test
|
||||
|
||||
db.test.remove({})
|
||||
db.test.save({"i": 1})
|
||||
|
||||
db.test.update({"i": 1}, {"$set": {"i": 2}})
|
||||
self.assert_(db.last_status()["updatedExisting"])
|
||||
|
||||
db.test.update({"i": 1}, {"$set": {"i": 500}})
|
||||
self.failIf(db.last_status()["updatedExisting"])
|
||||
|
||||
def test_password_digest(self):
|
||||
db = self.connection.pymongo_test
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user