def test_should_be_created(db_str, db_cursor, table): table.interval = 20 assert should_be_created(db_str, table) is True mark_table_as_waiting(db_str, table.name) assert should_be_created(db_str, table) is False mark_table_as_not_waiting(db_str, table.name) assert should_be_created(db_str, table) is True old = arrow.now().replace(minutes=-180).timestamp db_cursor.execute( """ UPDATE tables SET waiting = ? WHERE table_name = ? """, (old, table.name), ) assert should_be_created(db_str, table) is True start = arrow.now().replace(seconds=-180).timestamp log_start(db_str, table.name, start) assert should_be_created(db_str, table) is True table.last_created = start assert should_be_created(db_str, table) is False
def test_is_running(db_str): assert is_running(db_str, "first.cities") is False start = arrow.now().replace(seconds=-180).timestamp log_start(db_str, "first.cities", start) assert is_running(db_str, "first.cities") is True assert is_running(db_str, "first.countries") is False
def test_get_time_running(db_str): start = arrow.now().replace(seconds=-180).timestamp log_start(db_str, "first.cities", start) time = get_time_running(db_str, "first.cities") assert time is not None assert time < 190 assert time >= 180 time = get_time_running(db_str, "first.countries") assert time is None
def test_reset_all_starts(db_str, db_cursor): log_start(db_str, "first.cities", 1522151835) log_start(db_str, "first.countries", 1522151855) reset_all_starts(db_str) db_cursor.execute(""" SELECT started FROM tables """) for row in db_cursor: assert row[0] is None
def test_log_start(db_str, db_cursor): log_start(db_str, "first.cities", 1522151835) db_cursor.execute(""" SELECT started FROM tables WHERE table_name == 'first.cities' """) assert db_cursor.fetchone()[0] == 1522151835 log_start(db_str, "non-existent", 1522151835) db_cursor.execute(""" SELECT started FROM tables WHERE table_name == 'first.cities' """) assert db_cursor.fetchone()[0] == 1522151835
def test_reset_start(db_str, db_cursor): log_start(db_str, "first.cities", 1522151835) reset_start(db_str, "first.countries") db_cursor.execute(""" SELECT started FROM tables WHERE table_name == 'first.cities' """) assert db_cursor.fetchone()[0] == 1522151835 reset_start(db_str, "first.cities") db_cursor.execute(""" SELECT started FROM tables WHERE table_name == 'first.cities' """) assert db_cursor.fetchone()[0] is None