def test_connect_by_dict(self): params = { 'user': '******', 'passwd': 'password', 'host': 'localhost', 'db': 'pydb_test' } db_context = kida.MySQLContext(params) db_context.close()
def teardown_module(): context = kida.MySQLContext({ 'user': '******', 'host': 'localhost', 'db': 'pydb_test' }) context.execute_sql('drop database pydb_test') context.execute_sql("drop user pydb_test@'localhost'") context.close() logging.debug('teardown module')
def setup_module(): context = kida.MySQLContext(user=manager_username, host=db_host) context.execute_sql('create database %s' % test_db) context.execute_sql('use %s' % test_db) context.execute_sql("create user '%s'@'localhost' IDENTIFIED BY '%s'" % (test_username, test_password)) context.execute_sql("GRANT ALL ON %s.* TO '%s'@'localhost';" % (test_db, test_username)) context.execute_sql(""" CREATE TABLE `table1` ( `id` int(11) NOT NULL auto_increment, `fint` int(11) DEFAULT NULL, `fstr` varchar(50) DEFAULT NULL, `flong` bigint(20) DEFAULT NULL, `fdate` date DEFAULT NULL, `fdatetime` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 """) context.execute_sql(""" create table table2 ( k1 int not null, k2 int not null, primary key (k2, k1)) """) context.execute_sql(''' create table users ( id int not null auto_increment primary key, username varchar(20) not null, constraint unique idx_users_username (username) ) ''') context.close() logging.debug('setup module')
def setUp(self): self.target = kida.MySQLContext(dburl=target_dburl) logging.debug('setUp') self.target.execute_sql('delete from table1') self.target.execute_sql('delete from table2') """ CREATE TABLE `table1` ( `id` int(11) NOT NULL auto_increment, `fint` int(11) DEFAULT NULL, `fstr` varchar(50) DEFAULT NULL, `flong` bigint(20) DEFAULT NULL, `fdate` date DEFAULT NULL, `fdatetime` datetime DEFAULT NULL, PRIMARY KEY (`id`), ) ENGINE=InnoDB DEFAULT CHARSET=latin1 """ """ create table table2 ( k1 int not null, k2 int not null, primary key (k2, k1)) """ '''
def test_connect_by_kwargs(self): db_context = kida.MySQLContext(user='******', host='localhost', port=3306, db='pydb_test') db_context.close()
def test_connect_by_url_no_username(self): dburl = 'mysql://root@localhost/pydb_test' db_context = kida.MySQLContext(dburl) db_context.close()
def test_connect_by_url_plus_user(self): dburl = 'mysql://localhost/pydb_test' db_context = kida.MySQLContext(dburl, user='******', passwd='password') db_context.close()
def test_connect_by_url(self): dburl = 'mysql://*****:*****@localhost/pydb_test' db_context = kida.MySQLContext(dburl) db_context.close()