better error messages for iterating on connection, database
This commit is contained in:
parent
163680bc16
commit
0955faca30
@ -228,3 +228,9 @@ class Connection(object):
|
||||
result = self[name]._command({"dropDatabase": 1})
|
||||
if result["ok"] != 1:
|
||||
raise OperationFailure("failed to drop database")
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
raise TypeError("'Connection' object is not iterable")
|
||||
|
||||
@ -237,3 +237,9 @@ class Database(object):
|
||||
"""Returns a list containing current profiling information.
|
||||
"""
|
||||
return list(self.system.profile.find())
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
raise TypeError("'Database' object is not iterable")
|
||||
|
||||
@ -101,5 +101,13 @@ class TestConnection(unittest.TestCase):
|
||||
dbs = connection.database_names()
|
||||
self.assertTrue("test" not in dbs)
|
||||
|
||||
def test_iteration(self):
|
||||
connection = Connection(self.host, self.port)
|
||||
|
||||
def iterate():
|
||||
[a for a in connection]
|
||||
|
||||
self.assertRaises(TypeError, iterate)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@ -155,6 +155,14 @@ class TestDatabase(unittest.TestCase):
|
||||
self.assertTrue(isinstance(info[0]["ts"], datetime.datetime))
|
||||
self.assertTrue(isinstance(info[0]["millis"], types.FloatType))
|
||||
|
||||
def test_iteration(self):
|
||||
db = self.connection.test
|
||||
|
||||
def iterate():
|
||||
[a for a in db]
|
||||
|
||||
self.assertRaises(TypeError, iterate)
|
||||
|
||||
def test_save_find_one(self):
|
||||
db = Database(self.connection, "test")
|
||||
db.test.remove({})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user