Esempio n. 1
0
    def test_configure(self):
        """Connection.configure"""
        test1 = 'mongodb://localhost/test1'
        test2 = 'mongodb://localhost/test2'
        prefix2 = 'units_'
        config = {
            'test1': test1,
            'test2': {
                'uri': test2,
                'prefix': prefix2,
            },
        }

        try:
            connection.configure(config)
            con1 = connection.get('test1')
            self.assertEqual(con1.prefix, "", "con1 prefix is incorrect")
            self.assertEqual(con1.database.name, "test1", "con1 database is incorrect")

            con2 = connection.get('test2')
            self.assertEqual(con2.prefix, prefix2, "con2 prefix is incorrect")
            self.assertEqual(con2.database.name, "test2", "con2 database is incorrect")

            self.assertRaises(
                errors.ConfigError, connection.configure, {'broken': ''})
            self.assertRaises(
                errors.ConfigError, connection.configure, {'broken': {'uri': ''}})
        finally:
            for name, con in six.iteritems(connection.connections):
                con.close()
Esempio n. 2
0
    def test_configure(self):
        """Connection.configure"""
        test1 = "mongodb://localhost/test1"
        test2 = "mongodb://localhost/test2"
        prefix2 = "units_"
        config = {"test1": test1, "test2": {"uri": test2, "prefix": prefix2}}

        try:
            connection.configure(config)
            con1 = connection.get("test1")
            self.assertTrue(con1.client.alive(), "con1 is not alive")
            self.assertEqual(con1.prefix, "", "con1 prefix is incorrect")
            self.assertEqual(con1.database.name, "test1", "con1 database is incorrect")

            con2 = connection.get("test2")
            self.assertTrue(con2.client.alive(), "con2 is not alive")
            self.assertEqual(con2.prefix, prefix2, "con2 prefix is incorrect")
            self.assertEqual(con2.database.name, "test2", "con2 database is incorrect")

            self.assertRaises(errors.ConfigError, connection.configure, {"broken": ""})
            self.assertRaises(errors.ConfigError, connection.configure, {"broken": {"uri": ""}})
        finally:
            for name, con in connection.connections.iteritems():
                con.close()
Esempio n. 3
0
 def setUp(self):
     """Create database connections."""
     connection.configure(self.config)
     self.con = list(connection.connections.values())[0]