def test_attrs(self):
        db = DBAggregator()
        self.assertFalse(hasattr(db, "my_db"))

        db.add("my_db", self.db_conn)
        self.assertTrue(hasattr(db, "my_db"))

        self.assertTrue(hasattr(db.my_db, "engine"))

        self.assertTrue(hasattr(db.my_db, "sigle_session"))
        self.assertTrue(callable(db.my_db.sigle_session))

        self.assertTrue(hasattr(db.my_db, "session"))
        self.assertTrue(callable(db.my_db.session))

        self.assertTrue(hasattr(db.my_db, "tables"))

        self.assertTrue(hasattr(db.my_db, "load_tables"))
        self.assertTrue(callable(db.my_db.load_tables))

        self.assertTrue(hasattr(db.my_db, "set_new_table"))
        self.assertTrue(callable(db.my_db.set_new_table))

        self.assertTrue(hasattr(db.my_db, "cursor"))
        self.assertTrue(callable(db.my_db.cursor))
Exemple #2
0
    def test_attrs(self):
        db = DBAggregator()
        self.assertFalse(hasattr(db, 'my_db'))

        db.add('my_db', self.db_conn)
        self.assertTrue(hasattr(db, 'my_db'))

        self.assertTrue(hasattr(db.my_db, 'engine'))

        self.assertTrue(hasattr(db.my_db, 'sigle_session'))
        self.assertTrue(callable(db.my_db.sigle_session))

        self.assertTrue(hasattr(db.my_db, 'session'))
        self.assertTrue(callable(db.my_db.session))

        self.assertTrue(hasattr(db.my_db, 'tables'))

        self.assertTrue(hasattr(db.my_db, 'load_tables'))
        self.assertTrue(callable(db.my_db.load_tables))

        self.assertTrue(hasattr(db.my_db, 'set_new_table'))
        self.assertTrue(callable(db.my_db.set_new_table))

        self.assertTrue(hasattr(db.my_db, 'cursor'))
        self.assertTrue(callable(db.my_db.cursor))
Exemple #3
0
    def test_load_table(self):
        self.db_conn = db_conn

        db = DBAggregator()
        db.add('db1', self.db_conn)
        conn = db.db1.engine.connect()

        if hasattr(db.db1.tables, 'TbY'):
            conn.execute('DROP TABLE tb_y')
        conn.execute('CREATE TABLE tb_y (a INTEGER PRIMARY KEY, b INTEGER)')

        if hasattr(db.db1.tables, 'TbZ'):
            conn.execute('DROP TABLE tb_z')
        conn.execute('CREATE TABLE tb_z (a INTEGER PRIMARY KEY, b INTEGER)')

        db.add('db2', self.db_conn)
        self.assertTrue(hasattr(db.db2.tables, 'TbX'))
        self.assertTrue(hasattr(db.db2.tables, 'TbY'))
        self.assertTrue(hasattr(db.db2.tables, 'TbZ'))

        db.add('db3', self.db_conn)
        db.db3.load_tables(['tb_x', 'tb_y'])
        self.assertTrue(hasattr(db.db3.tables, 'TbX'))
        self.assertTrue(hasattr(db.db3.tables, 'TbY'))
        self.assertFalse(hasattr(db.db3.tables, 'TbZ'))
    def setUp(self):
        self.db_conn = getattr(self, "db_conn", db_conn)

        db = DBAggregator()
        db.add("db1", self.db_conn)
        conn = db.db1.engine.connect()

        if hasattr(db.db1.tables, "TbX"):
            conn.execute("DROP TABLE tb_x")

        conn.execute("CREATE TABLE tb_x (a INTEGER PRIMARY KEY, b INTEGER)")
        conn.execute("INSERT INTO tb_x (a, b) VALUES (1, 10)")
        conn.execute("INSERT INTO tb_x (a, b) VALUES (2, 20)")

        db.add("db_test", self.db_conn)
        setattr(self, "db_test", db.db_test)
    def test_load_table(self):
        self.db_conn = db_conn

        db = DBAggregator()
        db.add("db1", self.db_conn)
        conn = db.db1.engine.connect()

        if hasattr(db.db1.tables, "TbY"):
            conn.execute("DROP TABLE tb_y")
        conn.execute("CREATE TABLE tb_y (a INTEGER PRIMARY KEY, b INTEGER)")

        if hasattr(db.db1.tables, "TbZ"):
            conn.execute("DROP TABLE tb_z")
        conn.execute("CREATE TABLE tb_z (a INTEGER PRIMARY KEY, b INTEGER)")

        db.add("db2", self.db_conn)
        self.assertTrue(hasattr(db.db2.tables, "TbX"))
        self.assertTrue(hasattr(db.db2.tables, "TbY"))
        self.assertTrue(hasattr(db.db2.tables, "TbZ"))

        db.add("db3", self.db_conn)
        db.db3.load_tables(["tb_x", "tb_y"])
        self.assertTrue(hasattr(db.db3.tables, "TbX"))
        self.assertTrue(hasattr(db.db3.tables, "TbY"))
        self.assertFalse(hasattr(db.db3.tables, "TbZ"))
    def test_session_insert(self):
        tbl = self.db_test.tables
        sess = self.db_test.session()

        row = tbl.TbX()
        row.a = 3
        row.b = 30
        sess.add(row)
        sess.commit()

        db = DBAggregator()
        db.add("db2", self.db_conn)

        tbl2 = db.db2.tables
        sess2 = db.db2.session()

        q = sess2.query(tbl2.TbX)
        q = q.filter(tbl2.TbX.a == 3)
        q = q.filter(tbl2.TbX.b == 30)
        self.assertEqual(1, q.count())
Exemple #7
0
def aggregate_by_iniconf(iniconf_list,
                         sections=None,
                         db_aggregator=None,
                         engine_args=None):
    db = db_aggregator or DBAggregator()

    for session, conn_string in conn_str_by_iniconf(iniconf_list,
                                                    sections).iteritems():
        db.add(session, conn_string, engine_args)

    return db
Exemple #8
0
    def test_session_insert(self):
        tbl = self.db_test.tables
        sess = self.db_test.session()

        row = tbl.TbX()
        row.a = 3
        row.b = 30
        sess.add(row)
        sess.commit()

        db = DBAggregator()
        db.add('db2', self.db_conn)

        tbl2 = db.db2.tables
        sess2 = db.db2.session()

        q = sess2.query(tbl2.TbX)
        q = q.filter(tbl2.TbX.a == 3)
        q = q.filter(tbl2.TbX.b == 30)
        self.assertEqual(1, q.count())
Exemple #9
0
    def setUp(self):
        self.db_conn = getattr(self, 'db_conn', db_conn)

        db = DBAggregator()
        db.add('db1', self.db_conn)
        conn = db.db1.engine.connect()

        if hasattr(db.db1.tables, 'TbX'):
            conn.execute('DROP TABLE tb_x')

        conn.execute('CREATE TABLE tb_x (a INTEGER PRIMARY KEY, b INTEGER)')
        conn.execute('INSERT INTO tb_x (a, b) VALUES (1, 10)')
        conn.execute('INSERT INTO tb_x (a, b) VALUES (2, 20)')

        db.add('db_test', self.db_conn)
        setattr(self, 'db_test', db.db_test)