from datetime import timedelta, datetime from .checkin_db import CheckinDB TEST_DB_NAME = "test.db" checkin_db = CheckinDB(TEST_DB_NAME) checkin_db.clear_rows() def test_get_present_count() -> None: checkin_db.update("Alice", True) checkin_db.update("Bob", True) checkin_db.update("Bob", False) checkin_db.update("Bob", True) assert checkin_db.get_checkin_count() == 2 def test_present_names() -> None: assert checkin_db.get_checkin_names() == ["Alice", "Bob"] def test_updated_timestamp() -> None: assert checkin_db.get_updated_for_name( "Alice" ) >= datetime.now() - timedelta(minutes=1) def test_auto_checkout() -> None: assert "Alice" in checkin_db.get_checkin_names() old_timestamp = (datetime.now() - timedelta(hours=6)).timestamp() with checkin_db.con: checkin_db.con.execute( f"UPDATE checkin SET updated = {old_timestamp} WHERE name = 'Alice'" ) checkin_db.auto_checkout() assert "Alice" not in checkin_db.get_checkin_names()