def testConnect(self): self.connection = MySQLConnection() self.connection.host = 'localhost' self.connection.user = '******' self.connection.passwd = 'y47test' self.connection.database = 'y47test' db = self.connection.connect self.assertTrue('_mysql.connection' in repr(db)) db.close()
def testConnectPasswdNotSet(self): self.connection = MySQLConnection(host='localhost', user='******', database='y47test') with self.assertRaises(ValueError): self.connection.connect()
def testAutoCommitIsDisabled(self): self.connection = MySQLConnection() self.connection.autocommit = 0 self.assertEqual(self.connection.autocommit, 0)
def testConnectHostNotSet(self): self.connection = MySQLConnection(user='******', passwd='y47test', database='y47test') with self.assertRaises(ValueError): self.connection.connect()
def testDbIsNotNone(self): self.connection = MySQLConnection() self.connection.database = 'y47test' self.assertEqual(self.connection.database, 'y47test')
def testAutoCommitIsEnabled(self): self.connection = MySQLConnection() self.connection.autocommit = 1 self.assertEqual(self.connection.autocommit, 1)
def testPasswdIsNotNone(self): self.connection = MySQLConnection() self.connection.passwd = 'y47test' self.assertEqual(self.connection.passwd, 'y47test')
def testDbIsNone(self): self.connection = MySQLConnection() self.connection.database = None self.assertEqual(self.connection.database, None)
def testUserIsNotNone(self): self.connection = MySQLConnection() self.connection.user = '******' self.assertEqual(self.connection.user, 'y47test')
def testPasswdIsNone(self): self.connection = MySQLConnection() self.connection.passwd = None self.assertEqual(self.connection.passwd, None)
def testUserIsNone(self): self.connection = MySQLConnection() self.connection.user = None self.assertEqual(self.connection.user, None)
def testHostIsNotNone(self): self.connection = MySQLConnection() self.connection.host = 'localhost' self.assertEqual(self.connection.host, 'localhost')
def testHostIsNone(self): self.connection = MySQLConnection() self.connection.host = None self.assertEqual(self.connection.host, None)
def testInitAutoCommitIsOneByDefault(self): self.connection = MySQLConnection() self.assertEqual(self.connection.autocommit, 1)
class TestMySQLConnection(unittest.TestCase): # host from __init__ def testInitHostIsNone(self): self.connection = MySQLConnection(host=None) self.assertEqual(self.connection.host, None) def testInitHostIsNotNone(self): self.connection = MySQLConnection(host='localhost') self.assertEqual(self.connection.host, 'localhost') # user from __init__ def testInitUserIsNone(self): self.connection = MySQLConnection(user=None) self.assertEqual(self.connection.user, None) def testInitUserIsNotNone(self): self.connection = MySQLConnection(user='******') self.assertEqual(self.connection.user, 'y47test') # passwd from __init__ def testInitPasswdIsNone(self): self.connection = MySQLConnection(passwd=None) self.assertEqual(self.connection.passwd, None) def testInitPasswdIsNotNone(self): self.connection = MySQLConnection(passwd='y47test') self.assertEqual(self.connection.passwd, 'y47test') # database from __init__ def testInitDbIsNone(self): self.connection = MySQLConnection(database=None) self.assertEqual(self.connection.database, None) def testInitDbIsNotNone(self): self.connection = MySQLConnection(database='y47test') self.assertEqual(self.connection.database, 'y47test') # autocommit from __init__ def testInitAutoCommitIsOneByDefault(self): self.connection = MySQLConnection() self.assertEqual(self.connection.autocommit, 1) def testInitAutoCommitIsEnabled(self): self.connection = MySQLConnection(autocommit=1) self.assertEqual(self.connection.autocommit, 1) def testInitAutoCommitIsDisabled(self): self.connection = MySQLConnection(autocommit=0) self.assertEqual(self.connection.autocommit, 0) # host property def testHostIsNone(self): self.connection = MySQLConnection() self.connection.host = None self.assertEqual(self.connection.host, None) def testHostIsNotNone(self): self.connection = MySQLConnection() self.connection.host = 'localhost' self.assertEqual(self.connection.host, 'localhost') # user property def testUserIsNone(self): self.connection = MySQLConnection() self.connection.user = None self.assertEqual(self.connection.user, None) def testUserIsNotNone(self): self.connection = MySQLConnection() self.connection.user = '******' self.assertEqual(self.connection.user, 'y47test') # passwd property def testPasswdIsNone(self): self.connection = MySQLConnection() self.connection.passwd = None self.assertEqual(self.connection.passwd, None) def testPasswdIsNotNone(self): self.connection = MySQLConnection() self.connection.passwd = 'y47test' self.assertEqual(self.connection.passwd, 'y47test') # database property def testDbIsNone(self): self.connection = MySQLConnection() self.connection.database = None self.assertEqual(self.connection.database, None) def testDbIsNotNone(self): self.connection = MySQLConnection() self.connection.database = 'y47test' self.assertEqual(self.connection.database, 'y47test') # autocommit property def testAutoCommitIsEnabled(self): self.connection = MySQLConnection() self.connection.autocommit = 1 self.assertEqual(self.connection.autocommit, 1) def testAutoCommitIsDisabled(self): self.connection = MySQLConnection() self.connection.autocommit = 0 self.assertEqual(self.connection.autocommit, 0) # connect def testConnectHostNotSet(self): self.connection = MySQLConnection(user='******', passwd='y47test', database='y47test') with self.assertRaises(ValueError): self.connection.connect() def testConnectUserNotSet(self): self.connection = MySQLConnection(host='localhost', passwd='y47test', database='y47test') with self.assertRaises(ValueError): self.connection.connect() def testConnectPasswdNotSet(self): self.connection = MySQLConnection(host='localhost', user='******', database='y47test') with self.assertRaises(ValueError): self.connection.connect() def testConnect(self): self.connection = MySQLConnection() self.connection.host = 'localhost' self.connection.user = '******' self.connection.passwd = 'y47test' self.connection.database = 'y47test' db = self.connection.connect self.assertTrue('_mysql.connection' in repr(db)) db.close()