示例#1
0
    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()
示例#2
0
 def testConnectPasswdNotSet(self):
     self.connection = MySQLConnection(host='localhost', user='******',
                                         database='y47test')
     with self.assertRaises(ValueError):
         self.connection.connect()
示例#3
0
 def testAutoCommitIsDisabled(self):
     self.connection = MySQLConnection()
     self.connection.autocommit = 0
     self.assertEqual(self.connection.autocommit, 0)
示例#4
0
 def testConnectHostNotSet(self):
     self.connection = MySQLConnection(user='******', passwd='y47test',
                                         database='y47test')
     with self.assertRaises(ValueError):
         self.connection.connect()
示例#5
0
 def testDbIsNotNone(self):
     self.connection = MySQLConnection()
     self.connection.database = 'y47test'
     self.assertEqual(self.connection.database, 'y47test')
示例#6
0
 def testAutoCommitIsEnabled(self):
     self.connection = MySQLConnection()
     self.connection.autocommit = 1
     self.assertEqual(self.connection.autocommit, 1)
示例#7
0
 def testPasswdIsNotNone(self):
     self.connection = MySQLConnection()
     self.connection.passwd = 'y47test'
     self.assertEqual(self.connection.passwd, 'y47test')
示例#8
0
 def testDbIsNone(self):
     self.connection = MySQLConnection()
     self.connection.database = None
     self.assertEqual(self.connection.database, None)
示例#9
0
 def testUserIsNotNone(self):
     self.connection = MySQLConnection()
     self.connection.user = '******'
     self.assertEqual(self.connection.user, 'y47test')
示例#10
0
 def testPasswdIsNone(self):
     self.connection = MySQLConnection()
     self.connection.passwd = None
     self.assertEqual(self.connection.passwd, None)
示例#11
0
 def testUserIsNone(self):
     self.connection = MySQLConnection()
     self.connection.user = None
     self.assertEqual(self.connection.user, None)
示例#12
0
 def testHostIsNotNone(self):
     self.connection = MySQLConnection()
     self.connection.host = 'localhost'
     self.assertEqual(self.connection.host, 'localhost')
示例#13
0
 def testHostIsNone(self):
     self.connection = MySQLConnection()
     self.connection.host = None
     self.assertEqual(self.connection.host, None)
示例#14
0
 def testInitAutoCommitIsOneByDefault(self):
     self.connection = MySQLConnection()
     self.assertEqual(self.connection.autocommit, 1)
示例#15
0
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()