Example #1
0
    def test_constants(self):
        Connection.HOST = self.host
        Connection.PORT = self.port
        self.assert_(Connection())

        Connection.HOST = "somedomainthatdoesntexist.org"
        Connection.PORT = 123456789
        self.assertRaises(ConnectionFailure, Connection)
        self.assert_(Connection(self.host, self.port))

        Connection.HOST = self.host
        Connection.PORT = self.port
        self.assert_(Connection())
Example #2
0
    def test_database_names(self):
        connection = Connection(io_loop = self.io_loop)
        
        def callback2(dbs):
            self.assert_("pymongo_test" in dbs)
            self.stop()
            
            
        def callback(resp):       
            connection.database_names(callback2)   
                        
        connection.pymongo_test.test.save({"dummy": u"object"})

        
        self.wait()
Example #3
0
    def test_get_db(self):
        connection = Connection(self.host, self.port)

        def make_db(base, name):
            return base[name]

        self.assertRaises(InvalidName, make_db, connection, "")
        self.assertRaises(InvalidName, make_db, connection, "te$t")
        self.assertRaises(InvalidName, make_db, connection, "te.t")
        self.assertRaises(InvalidName, make_db, connection, "te\\t")
        self.assertRaises(InvalidName, make_db, connection, "te/t")
        self.assertRaises(InvalidName, make_db, connection, "te st")

        self.assert_(isinstance(connection.test, Database))
        self.assertEqual(connection.test, connection["test"])
        self.assertEqual(connection.test, Database(connection, "test"))
Example #4
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Simple script to help test auto-reconnection."""

import sys
import threading
import time
sys.path[0:0] = [""]

from apymongo.errors import AutoReconnect
from apymongo.connection import Connection

db = Connection.paired(("localhost", 27018)).test
db.test.remove({})

class Something(threading.Thread):
    def run(self):
        while True:
            time.sleep(1)
            try:
                id = db.test.save({"x": 1}, safe=True)
                assert db.test.find_one(id)["x"] == 1
                db.test.remove(id)
                db.connection.end_request()
                print "Y"
            except AutoReconnect, e:
                print e
                print "N"
Example #5
0
 def test_getters(self):
     self.assertEqual(Connection(self.host, self.port).host, self.host)
     self.assertEqual(Connection(self.host, self.port).port, self.port)
     self.assertEqual(set([(self.host, self.port)]), Connection(self.host, self.port).nodes)
Example #6
0
 def test_repr(self):
     self.assertEqual(repr(Connection(self.host, self.port)),
                      "Connection('%s', %s)" % (self.host, self.port))
Example #7
0
 def test_host_w_port(self):
     self.assert_(Connection("%s:%d" % (self.host, self.port)))
     self.assertRaises(ConnectionFailure, Connection,
                       "%s:123456789" % self.host, self.port)
Example #8
0
    def test_connect(self):
        self.assertRaises(ConnectionFailure, Connection,
                          "somedomainthatdoesntexist.org")
        self.assertRaises(ConnectionFailure, Connection, self.host, 123456789)

        self.assert_(Connection(self.host, self.port))
Example #9
0
def get_connection(*args, **kwargs):
    host = os.environ.get("DB_IP", "localhost")
    port = int(os.environ.get("DB_PORT", 27017))
    return Connection(host, port, *args, **kwargs)