Added logging to display message when outside booking window in booker.py Added error handling for asyncio.run in crossfit_booker.py Added logging for errors during booking process
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify booking window functionality.
|
|
"""
|
|
import os
|
|
import sys
|
|
import logging
|
|
from datetime import datetime, timedelta
|
|
import pytz
|
|
|
|
# Add the parent directory to the path
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from src.crossfit_booker import CrossFitBooker
|
|
from src.booker import Booker
|
|
from src.auth import AuthHandler
|
|
|
|
# Set up logging
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
# Mock the login method to avoid actual authentication
|
|
def mock_login(self) -> bool:
|
|
self.auth_token = "mock_token"
|
|
self.user_id = "12345"
|
|
return True
|
|
|
|
# Test the booking window functionality
|
|
def test_booking_window():
|
|
"""Test the booking window functionality."""
|
|
# Create a booker instance
|
|
booker = CrossFitBooker()
|
|
|
|
# Replace the login method with our mock
|
|
original_login = AuthHandler.login
|
|
AuthHandler.login = mock_login
|
|
|
|
# Set up timezone and target time
|
|
tz = pytz.timezone("Europe/Paris")
|
|
current_time = datetime.now(tz)
|
|
|
|
# Get the target time from the environment variable or use default
|
|
target_time_str = os.environ.get("TARGET_RESERVATION_TIME", "20:01")
|
|
target_hour, target_minute = map(int, target_time_str.split(":"))
|
|
target_time = current_time.replace(hour=target_hour, minute=target_minute, second=0, microsecond=0)
|
|
|
|
# Calculate booking window end
|
|
booking_window_end = target_time + timedelta(minutes=10)
|
|
|
|
# Display current time and booking window
|
|
logging.info(f"Current time: {current_time}")
|
|
logging.info(f"Target booking time: {target_time}")
|
|
logging.info(f"Booking window end: {booking_window_end}")
|
|
|
|
# Check if we're in the booking window
|
|
if target_time <= current_time <= booking_window_end:
|
|
logging.info("We are within the booking window!")
|
|
else:
|
|
logging.info("We are outside the booking window.")
|
|
time_diff = (target_time - current_time).total_seconds()
|
|
logging.info(f"Next booking window starts in: {time_diff//60} minutes and {time_diff%60:.0f} seconds")
|
|
|
|
# Restore the original login method
|
|
AuthHandler.login = original_login
|
|
|
|
if __name__ == "__main__":
|
|
test_booking_window() |