def testQueryingOracleWithValidlyFormattedArguments(self):
        cursor = self.mock()
        cursor.expects(once()).method("execute")
        cursor.expects(once()).method("fetchall").will(return_value([("workDir", "reloadDir", "archiveDir", "oid1")]))

        conn = self.mock()
        conn.expects(once()).method("cursor").will(return_value(cursor))

        sys.modules["cx_Oracle"] = self.mock()
        sys.modules["cx_Oracle"].expects(once()).method("connect").will(return_value(conn))
        
        connection_factory = factory.cxoraConnectionFactory(username="******", password="******", hostname="localhost", db="mock")
        dt = DatabaseTemplate(connection_factory)

        dt.query(""" 
                SELECT
                    impcarrcfg.paystat_work_dir, 
                    impcarrcfg.paystat_reload_dir,
                    impcarrcfg.paystat_archive_dir,
                    impcarrcfg.oid 
                FROM impcarrcfg, carr, lklabelsys 
                WHERE (lklabelsys.oid = impcarrcfg.lklabelsys_oid)
                and (carr.oid = impcarrcfg.carr_oid )
                and (carr.oid = :carr_oid and lklabelsys.oid = :lklabelsys_oid) 
            """,
            {'carr_oid':5, 'lklabelsys_oid':5},
            testSupportClasses.ImpFilePropsRowMapper())

        del(sys.modules["cx_Oracle"])
    def testQueryingOracleWithValidlyFormattedArguments(self):
        cursor = self.mock()
        cursor.expects(once()).method("execute")
        cursor.expects(once()).method("fetchall").will(return_value([("workDir", "reloadDir", "archiveDir", "oid1")]))

        conn = self.mock()
        conn.expects(once()).method("cursor").will(return_value(cursor))
        conn.expects(once()).method("close")

        sys.modules["cx_Oracle"] = self.mock()
        sys.modules["cx_Oracle"].expects(once()).method("connect").will(return_value(conn))
        
        connection_factory = factory.cxoraConnectionFactory(username="******", password="******", hostname="localhost", db="mock")
        dt = DatabaseTemplate(connection_factory)

        dt.query(""" 
                SELECT
                    impcarrcfg.paystat_work_dir, 
                    impcarrcfg.paystat_reload_dir,
                    impcarrcfg.paystat_archive_dir,
                    impcarrcfg.oid 
                FROM impcarrcfg, carr, lklabelsys 
                WHERE (lklabelsys.oid = impcarrcfg.lklabelsys_oid)
                and (carr.oid = impcarrcfg.carr_oid )
                and (carr.oid = :carr_oid and lklabelsys.oid = :lklabelsys_oid) 
            """,
            {'carr_oid':5, 'lklabelsys_oid':5},
            testSupportClasses.ImpFilePropsRowMapper())

        del(sys.modules["cx_Oracle"])
    def testConnectingToOracle(self):
        sys.modules["cx_Oracle"] = self.mock()
        sys.modules["cx_Oracle"].expects(once()).method("connect")
        
        connection_factory = factory.cxoraConnectionFactory(username="******", password="******", hostname="localhost", db="mock")
        connection = connection_factory.connect()

        del(sys.modules["cx_Oracle"])
    def testConnectingToOracle(self):
        sys.modules["cx_Oracle"] = self.mock()
        sys.modules["cx_Oracle"].expects(once()).method("connect")
        
        connection_factory = factory.cxoraConnectionFactory(username="******", password="******", hostname="localhost", db="mock")
        connection = connection_factory.connect()

        del(sys.modules["cx_Oracle"])
    def testInsertingIntoOracleWithInvalidlyFormattedArgumentsWithInsertApi(self):
        sys.modules["cx_Oracle"] = self.mock()

        connection_factory = factory.cxoraConnectionFactory(username="******", password="******", hostname="localhost", db="mock")
        dt = DatabaseTemplate(connection_factory)

        self.assertRaises(InvalidArgumentType, dt.insert_and_return_id,
            "INSERT INTO T_UNIT (F_UNIT_PK, F_UNIT_ID, F_NAME) VALUES (?, ?, ?)",
            (1,1,1))

        del(sys.modules["cx_Oracle"])
    def testQueryingOracleWithInvalidlyFormattedArguments(self):
        sys.modules["cx_Oracle"] = self.mock()
        
        connection_factory = factory.cxoraConnectionFactory(username="******", password="******", hostname="localhost", db="mock")
        dt = DatabaseTemplate(connection_factory)

        self.assertRaises(InvalidArgumentType, dt.query, """ 
                SELECT
                    impcarrcfg.paystat_work_dir, 
                    impcarrcfg.paystat_reload_dir,
                    impcarrcfg.paystat_archive_dir,
                    impcarrcfg.oid 
                FROM impcarrcfg, carr, lklabelsys 
                WHERE (lklabelsys.oid = impcarrcfg.lklabelsys_oid)
                and (carr.oid = impcarrcfg.carr_oid )
                and (carr.oid = ? and lklabelsys.oid = ?) 
            """, (5, 5), testSupportClasses.ImpFilePropsRowMapper())

        del(sys.modules["cx_Oracle"])