Beispiel #1
0
    def test_conn_slave(self):
        conn_info = db.ConnectionInfo(self.username, self.password, self.master, self.slaves)

        self.assertEqual(self.master, conn_info.master_ip)
        self.assertIn(conn_info.slave_ip, self.slave_ips)
        self.assertEqual(self.slave_ips, conn_info.slave_ips)
        self.assertTrue(conn_info.replicating())
Beispiel #2
0
    def test_conn_master(self):
        conn_info = db.ConnectionInfo(self.username, self.password, self.master, [])

        self.assertEqual(self.master, conn_info.master_ip)
        self.assertEqual(self.master, conn_info.slave_ip)
        self.assertEqual([self.master], conn_info.slave_ips)
        self.assertFalse(conn_info.replicating())
Beispiel #3
0
 def get_db_config(self, _):
     """
     We use this method to let test methods override the DB config in
     realtime
     We need to accept a path argument (the app will pass one to us),
     we ignore it.
     """
     return db.ConnectionInfo(**self.db_config)
Beispiel #4
0
def load_config_from_env():
    kwargs = {}

    try:
        for var, attr in ENV_CONFIG_STRUCTURE:
            kwargs[attr] = os.environ[var]
    except KeyError:
        return None

    return db.ConnectionInfo(**kwargs)
Beispiel #5
0
def parse_config(path):
    """
    Parse config files at `path` with a structure as defined in
    CONFIG_STRUCTURE
    """
    kwargs = {}

    for fname, attr in CONFIG_STRUCTURE:
        try:
            with open(os.path.join(path, fname)) as cnf_file:
                kwargs[attr] = cnf_file.read().strip()
        except IOError:
            raise exceptions.NoConnectionInfo()

    return db.ConnectionInfo(**kwargs)
Beispiel #6
0
 def setUp(self):
     self.conn_info = db.ConnectionInfo(**TEST_DB_CONFIG)