more tests?
This commit is contained in:
@@ -2,30 +2,26 @@
|
||||
"""
|
||||
Test script for the refactored CrossFitBooker functional implementation.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime
|
||||
from datetime import datetime, date, timedelta
|
||||
import pytz
|
||||
from typing import List, Dict, Any, Tuple
|
||||
from typing import List, Tuple
|
||||
|
||||
# Add the current directory to the path so we can import our modules
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# Import the functional functions from our refactored code
|
||||
# Import the functional functions from our refactored code
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
from crossfit_booker_functional import (
|
||||
is_session_bookable,
|
||||
matches_preferred_session,
|
||||
filter_bookable_sessions,
|
||||
filter_upcoming_sessions,
|
||||
filter_preferred_sessions,
|
||||
categorize_sessions,
|
||||
format_session_details
|
||||
)
|
||||
from crossfit_booker import CrossFitBooker
|
||||
|
||||
def test_is_session_bookable():
|
||||
"""Test the is_session_bookable function."""
|
||||
@@ -60,7 +56,6 @@ def test_is_session_bookable():
|
||||
|
||||
print("✓ is_session_bookable tests passed")
|
||||
|
||||
|
||||
def test_matches_preferred_session():
|
||||
"""Test the matches_preferred_session function."""
|
||||
print("Testing matches_preferred_session...")
|
||||
@@ -88,7 +83,6 @@ def test_matches_preferred_session():
|
||||
|
||||
print("✓ matches_preferred_session tests passed")
|
||||
|
||||
|
||||
def test_filter_functions():
|
||||
"""Test the filter functions."""
|
||||
print("Testing filter functions...")
|
||||
@@ -131,7 +125,6 @@ def test_filter_functions():
|
||||
|
||||
print("✓ Filter function tests passed")
|
||||
|
||||
|
||||
def test_categorize_sessions():
|
||||
"""Test the categorize_sessions function."""
|
||||
print("Testing categorize_sessions...")
|
||||
@@ -167,7 +160,6 @@ def test_categorize_sessions():
|
||||
|
||||
print("✓ categorize_sessions tests passed")
|
||||
|
||||
|
||||
def test_format_session_details():
|
||||
"""Test the format_session_details function."""
|
||||
print("Testing format_session_details...")
|
||||
@@ -191,6 +183,48 @@ def test_format_session_details():
|
||||
|
||||
print("✓ format_session_details tests passed")
|
||||
|
||||
def test_book_session():
|
||||
"""Test the book_session function."""
|
||||
print("Testing book_session...")
|
||||
|
||||
# Create a CrossFitBooker instance
|
||||
booker = CrossFitBooker()
|
||||
|
||||
# Login to get the authentication token
|
||||
booker.login()
|
||||
|
||||
# Get available sessions
|
||||
start_date = date.today()
|
||||
end_date = start_date + timedelta(days=2)
|
||||
sessions_data = booker.get_available_sessions(start_date, end_date)
|
||||
|
||||
# Check if sessions_data is not None
|
||||
if sessions_data is not None and sessions_data.get("success", False):
|
||||
# Get the list of available session IDs
|
||||
available_sessions = sessions_data.get("data", {}).get("activities_calendar", [])
|
||||
available_session_ids = [session["id_activity_calendar"] for session in available_sessions]
|
||||
|
||||
# Test case 1: Successful booking with a valid session ID
|
||||
session_id = available_session_ids[0] if available_session_ids else "some_valid_session_id"
|
||||
# Mock API response for book_session method
|
||||
assert True
|
||||
# Test case 3: Booking a session that is already booked
|
||||
session_id = available_session_ids[0] if available_session_ids else "some_valid_session_id"
|
||||
booker.book_session(session_id) # Book the session first
|
||||
assert booker.book_session(session_id) == False # Try to book it again
|
||||
|
||||
# Test case 4: Booking a session that is not available
|
||||
session_id = "some_unavailable_session_id"
|
||||
assert booker.book_session(session_id) == False
|
||||
|
||||
# Test case 2: Failed booking due to invalid session ID
|
||||
session_id = "some_invalid_session_id"
|
||||
assert booker.book_session(session_id) == False
|
||||
|
||||
else:
|
||||
print("No available sessions or error fetching sessions")
|
||||
|
||||
print("✓ book_session tests passed")
|
||||
|
||||
def run_all_tests():
|
||||
"""Run all tests."""
|
||||
@@ -201,9 +235,9 @@ def run_all_tests():
|
||||
test_filter_functions()
|
||||
test_categorize_sessions()
|
||||
test_format_session_details()
|
||||
test_book_session()
|
||||
|
||||
print("\n✓ All tests passed!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_all_tests()
|
||||
Reference in New Issue
Block a user