Adds unit tests for db_task_history, bug fixes

Uses sqlite3 in memory mode for db.
If sqlalchemy can't be imported, skips the test rather than failing.