示例#1
0
task_from_db = Task.query.get(task_id)

# now query the total_logged_seconds
benchmark_start = time.time()
total_logged_seconds = task_from_db.total_logged_seconds
benchmark_end = time.time()
print('total_logged_seconds: %s sec' % total_logged_seconds)
print('old way worked in: %s sec' % (benchmark_end - benchmark_start))

# now use the new way of doing it
benchmark_start = time.time()
quick_total_logged_seconds = task_from_db.total_logged_seconds
benchmark_end = time.time()
print('quick_total_logged_seconds: %s sec' % quick_total_logged_seconds)
print('new way worked in: %s sec' % (benchmark_end - benchmark_start))
assert total_logged_seconds == quick_total_logged_seconds

# clean up test database
DBSession.rollback()
connection = DBSession.connection()
engine = connection.engine
connection.close()

Base.metadata.drop_all(engine, checkfirst=True)
DBSession.remove()

stalker.defaults.timing_resolution = datetime.timedelta(hours=1)

DBSession.close_all()
drop_db(database_name)
示例#2
0
 def tearDownClass(cls):
     """tear down once
     """
     from stalker.db.session import DBSession
     DBSession.close_all()
     drop_db(cls.database_name)