I know this question has been asked many times before, but I have some concrete code examples and I wanted to know whether it makes sense to unit test them:
class FooAPI(object):
def create(self, prop1, prop2, prop3, prop4, prop5):
sql = "INSERT INTO foo (prop1, prop2, prop3) VALUES (?, ?, ?)"
self.connection.execute(sql, (prop1, prop2, prop3))
foo_id = self.connection.insert_id()
sql = "INSERT INTO foo_settings (foo_id, prop4, prop5) VALUES (?, ?, ?)"
self.connection.execute(sql, (foo_id, prop4, prop5))
return foo_id
def update(self, foo_id, prop1, prop2, prop3, prop4, prop5):
"Update code similar to above"
def delete(self, foo_id):
sql = "DELETE FROM foo WHERE foo_id = ?"
self.connection.execute(sql, (foo_id,))
def find(self, foo_id=None, prop1=None):
"Find objects by ID or by prop1"
Does it make sense to unit-test the above code, and how would one go about this. There are two complicating factors here:
- The database itself is not trivial and I currently have no easy way to create a database with all test data
- The schema is evolving, meaning that it's impossible to create a test database once and for all.