mardi 7 juillet 2015

in flask unit test,How to mock database connection and query execution in flask

I have a flask application that is setting up a database connection and executing queries,very similar to this:

        g['db'] = mysql.connector.connect("credentials")
        update = 'UPDATE table SET name =%s WHERE id=%s'
        cursor.execute(update, (nickname, idnum))

For unit testing ,I want to replace g['db'] and cursor.execute with mock objects.How to mock 'execute',database connection and set expectations?

Aucun commentaire:

Enregistrer un commentaire