I have two below functions in a class and I need to mock the database connection and cursor results. cx_Oracle.connect successfully patched it works as expected. But the cursor, callfunc, fetch_all doesn't get mock. Any idea what would be the correct syntax ?
class dbconnect:
def db_connect(self, connection_details):
connection = cx_Oracle.connect(user_name,pwd,<connection_string>)
return connection
def execute_function(self, sqlFunction, args):
cursor = self.connection.cursor()
res=cursor.callfunc(sqlFunction, cursor.var(cx_Oracle.CURSOR), args)
results = {'headers' : [x[0] for x in res.description],
'data': res.fetchall()
}
cursor.close()
return results
My Mocking code
with mock.patch('dbconnect.cx_Oracle.connect') as mockOracle:
result_set = {}
mockOracle.cursor.callfunc.fetch_all = result_set