Beispiel #1
0
 def testConnect(self):
     self.connection = OracleConnection()
     self.connection.host = 'localhost'
     self.connection.user = '******'
     self.connection.passwd = 'y47test'
     self.connection.sid = 'XE'
     db = self.connection.connect
     self.assertTrue('cx_Oracle.Connection' in repr(db))
     db.close()
Beispiel #2
0
 def testConnectSidNotSet(self):
     self.connection = OracleConnection(host='localhost', user='******',
                                         passwd='y47test')
     with self.assertRaises(ValueError):
         self.connection.connect()
Beispiel #3
0
 def testAutoCommitIsDisabled(self):
     self.connection = OracleConnection()
     self.connection.autocommit = 0
     self.assertEqual(self.connection.autocommit, 0)
Beispiel #4
0
 def testConnectHostNotSet(self):
     self.connection = OracleConnection(user='******', passwd='y47test',
                                         sid='XE')
     with self.assertRaises(ValueError):
         self.connection.connect()
Beispiel #5
0
 def testSidIsNone(self):
     self.connection = OracleConnection()
     self.connection.sid = None
     self.assertEqual(self.connection.sid, None)
Beispiel #6
0
 def testSidIsNotNone(self):
     self.connection = OracleConnection()
     self.connection.sid = 'XE'
     self.assertEqual(self.connection.sid, 'XE')
Beispiel #7
0
 def testPasswdIsNone(self):
     self.connection = OracleConnection()
     self.connection.passwd = None
     self.assertEqual(self.connection.passwd, None)
Beispiel #8
0
 def testPasswdIsNotNone(self):
     self.connection = OracleConnection()
     self.connection.passwd = 'y47test'
     self.assertEqual(self.connection.passwd, 'y47test')
Beispiel #9
0
 def testUserIsNone(self):
     self.connection = OracleConnection()
     self.connection.user = None
     self.assertEqual(self.connection.user, None)
Beispiel #10
0
 def testUserIsNotNone(self):
     self.connection = OracleConnection()
     self.connection.user = '******'
     self.assertEqual(self.connection.user, 'y47test')
Beispiel #11
0
 def testHostIsNotNone(self):
     self.connection = OracleConnection()
     self.connection.host = 'localhost'
     self.assertEqual(self.connection.host, 'localhost')
Beispiel #12
0
 def testHostIsNone(self):
     self.connection = OracleConnection()
     self.connection.host = None
     self.assertEqual(self.connection.host, None)
Beispiel #13
0
 def testInitAutoCommitIsEnabled(self):
     self.connection = OracleConnection(autocommit=1)
     self.assertEqual(self.connection.autocommit, 1)
Beispiel #14
0
 def testInitAutoCommitIsOneByDefault(self):
     self.connection = OracleConnection()
     self.assertEqual(self.connection.autocommit, 1)
Beispiel #15
0
class TestOracleConnection(unittest.TestCase):
    
    # host from __init__
    def testInitHostIsNone(self):
        self.connection = OracleConnection(host=None)
        self.assertEqual(self.connection.host, None)

    def testInitHostIsNotNone(self):
        self.connection = OracleConnection(host='localhost')
        self.assertEqual(self.connection.host, 'localhost')


    # user from __init__
    def testInitUserIsNone(self):
        self.connection = OracleConnection(user=None)
        self.assertEqual(self.connection.user, None)

    def testInitUserIsNotNone(self):
        self.connection = OracleConnection(user='******')
        self.assertEqual(self.connection.user, 'y47test')


    # passwd from __init__
    def testInitPasswdIsNone(self):
        self.connection = OracleConnection(passwd=None)
        self.assertEqual(self.connection.passwd, None)

    def testInitPasswdIsNotNone(self):
        self.connection = OracleConnection(passwd='y47test')
        self.assertEqual(self.connection.passwd, 'y47test')


    # sid from __init__
    def testInitSidIsNone(self):
        self.connection = OracleConnection(sid=None)
        self.assertEqual(self.connection.sid, None)

    def testInitSidIsNotNone(self):
        self.connection = OracleConnection(sid='XE')
        self.assertEqual(self.connection.sid, 'XE')


    # autocommit from __init__
    def testInitAutoCommitIsOneByDefault(self):
        self.connection = OracleConnection()
        self.assertEqual(self.connection.autocommit, 1)

    def testInitAutoCommitIsEnabled(self):
        self.connection = OracleConnection(autocommit=1)
        self.assertEqual(self.connection.autocommit, 1)

    def testInitAutoCommitIsDisabled(self):
        self.connection = OracleConnection(autocommit=0)
        self.assertEqual(self.connection.autocommit, 0)


    # host property
    def testHostIsNone(self):
        self.connection = OracleConnection()
        self.connection.host = None
        self.assertEqual(self.connection.host, None)

    def testHostIsNotNone(self):
        self.connection = OracleConnection()
        self.connection.host = 'localhost'
        self.assertEqual(self.connection.host, 'localhost')


    # user property
    def testUserIsNone(self):
        self.connection = OracleConnection()
        self.connection.user = None
        self.assertEqual(self.connection.user, None)

    def testUserIsNotNone(self):
        self.connection = OracleConnection()
        self.connection.user = '******'
        self.assertEqual(self.connection.user, 'y47test')


    # passwd property
    def testPasswdIsNone(self):
        self.connection = OracleConnection()
        self.connection.passwd = None
        self.assertEqual(self.connection.passwd, None)

    def testPasswdIsNotNone(self):
        self.connection = OracleConnection()
        self.connection.passwd = 'y47test'
        self.assertEqual(self.connection.passwd, 'y47test')


    # sid property
    def testSidIsNone(self):
        self.connection = OracleConnection()
        self.connection.sid = None
        self.assertEqual(self.connection.sid, None)

    def testSidIsNotNone(self):
        self.connection = OracleConnection()
        self.connection.sid = 'XE'
        self.assertEqual(self.connection.sid, 'XE')


    # autocommit property
    def testAutoCommitIsEnabled(self):
        self.connection = OracleConnection()
        self.connection.autocommit = 1
        self.assertEqual(self.connection.autocommit, 1)

    def testAutoCommitIsDisabled(self):
        self.connection = OracleConnection()
        self.connection.autocommit = 0
        self.assertEqual(self.connection.autocommit, 0)


    # connect
    def testConnectHostNotSet(self):
        self.connection = OracleConnection(user='******', passwd='y47test',
                                            sid='XE')
        with self.assertRaises(ValueError):
            self.connection.connect()


    def testConnectUserNotSet(self):
        self.connection = OracleConnection(host='localhost', passwd='y47test',
                                            sid='XE')
        with self.assertRaises(ValueError):
            self.connection.connect()


    def testConnectPasswdNotSet(self):
        self.connection = OracleConnection(host='localhost', user='******',
                                            sid='XE')
        with self.assertRaises(ValueError):
            self.connection.connect()


    def testConnectSidNotSet(self):
        self.connection = OracleConnection(host='localhost', user='******',
                                            passwd='y47test')
        with self.assertRaises(ValueError):
            self.connection.connect()


    def testConnect(self):
        self.connection = OracleConnection()
        self.connection.host = 'localhost'
        self.connection.user = '******'
        self.connection.passwd = 'y47test'
        self.connection.sid = 'XE'
        db = self.connection.connect
        self.assertTrue('cx_Oracle.Connection' in repr(db))
        db.close()