So I have a database class which has methods dedicated to specific actions. For example I have below method which accesses and writes to a table in the database:
def trackUserPerformance(self, verbform, verbsolution, erroneousUserInput, isVerbCorrect, date):
with self as db:
cursor = db.connection.cursor()
cursor.execute(
"INSERT INTO trackusersuccessfailure (verbform, verb, erroneousUserInput, state, date) VALUES "
"(%s, %s, %s, %s, %s)", (verbform, verbsolution, erroneousUserInput, isVerbCorrect, date))
self.connection.commit()
The method trackUserPerformance(...) is a method inside my database class. How do you for example rollback the query of the method trackUserPerformance(...) in tests? I personally like the idea of calling database methods like so:
db.specificMethod(...)
But it gets a little challenging when I need to test those method. My question is if my approach is even a good practice meaning to create methods that are responsible for specific database queries like the method above ore if this is not a good idea because of said challenge?