Permalink
Browse files

Missing import in connection.py and replica_set_connection.py

  • Loading branch information...
ajdavis committed Nov 29, 2012
1 parent 5cf8f03 commit 8af6705c5cae3060cd29a04152f686fed24b4768
Showing with 41 additions and 0 deletions.
  1. +2 −0 pymongo/connection.py
  2. +1 −0 pymongo/replica_set_connection.py
  3. +19 −0 test/test_connection.py
  4. +19 −0 test/test_replica_set_connection.py
View
@@ -37,6 +37,8 @@
Database(Connection('localhost', 27017), u'test-database')
"""
from pymongo.mongo_client import MongoClient
+from pymongo.errors import ConfigurationError
+
class Connection(MongoClient):
"""Connection to MongoDB.
@@ -34,6 +34,7 @@
Database(ReplicaSetConnection([u'...', u'...']), u'test_database')
"""
from pymongo.mongo_replica_set_client import MongoReplicaSetClient
+from pymongo.errors import ConfigurationError
class ReplicaSetConnection(MongoReplicaSetClient):
View
@@ -398,6 +398,25 @@ def test_timeouts(self):
conn = Connection(self.host, self.port, socketTimeoutMS=10500)
self.assertEqual(10.5, conn._MongoClient__pool.net_timeout)
+ def test_network_timeout_validation(self):
+ c = get_connection(network_timeout=10)
+ self.assertEqual(10, c._MongoClient__net_timeout)
+
+ c = get_connection(network_timeout=None)
+ self.assertEqual(None, c._MongoClient__net_timeout)
+
+ self.assertRaises(ConfigurationError,
+ get_connection, network_timeout=0)
+
+ self.assertRaises(ConfigurationError,
+ get_connection, network_timeout=-1)
+
+ self.assertRaises(ConfigurationError,
+ get_connection, network_timeout=1e10)
+
+ self.assertRaises(ConfigurationError,
+ get_connection, network_timeout='foo')
+
def test_network_timeout(self):
no_timeout = Connection(self.host, self.port)
timeout_sec = 1
@@ -468,6 +468,25 @@ def test_document_class(self):
self.assertFalse(isinstance(db.test.find_one(), SON))
c.close()
+ def test_network_timeout_validation(self):
+ c = self._get_connection(network_timeout=10)
+ self.assertEqual(10, c._MongoReplicaSetClient__net_timeout)
+
+ c = self._get_connection(network_timeout=None)
+ self.assertEqual(None, c._MongoReplicaSetClient__net_timeout)
+
+ self.assertRaises(ConfigurationError,
+ self._get_connection, network_timeout=0)
+
+ self.assertRaises(ConfigurationError,
+ self._get_connection, network_timeout=-1)
+
+ self.assertRaises(ConfigurationError,
+ self._get_connection, network_timeout=1e10)
+
+ self.assertRaises(ConfigurationError,
+ self._get_connection, network_timeout='foo')
+
def test_network_timeout(self):
no_timeout = self._get_connection()
timeout_sec = 1

0 comments on commit 8af6705

Please sign in to comment.