import json from pathlib import Path import pendulum import pytest from gestion_sport_connector import GestionSportsConnector from gestion_sports_services import GestionSportsServices from models import ( BookingFilter, BookingOpening, BookingPlatform, Club, Court, Sport, TotalBookings, Url, User, ) TEST_FOLDER = Path(__file__).parent.parent DATA_FOLDER = TEST_FOLDER / "data" RESPONSES_FOLDER = DATA_FOLDER / "responses" @pytest.fixture def court11() -> Court: return Court(id="1", name="Court 1", number=1, isIndoor=True) @pytest.fixture def court12() -> Court: return Court(id="2", name="Court 2", number=2, isIndoor=False) @pytest.fixture def court13() -> Court: return Court(id="3", name="Court 3", number=3, isIndoor=True) @pytest.fixture def court14() -> Court: return Court(id="4", name="Court 4", number=4, isIndoor=True) @pytest.fixture def sport1(court11: Court, court12: Court, court13: Court, court14: Court) -> Sport: return Sport( name="Sport1", id=8, duration=99, price=54, players=3, courts=[court11, court12, court13, court14], ) @pytest.fixture def court21() -> Court: return Court(id="1", name="Court 1", number=1, isIndoor=False) @pytest.fixture def court22() -> Court: return Court(id="2", name="Court 2", number=2, isIndoor=True) @pytest.fixture def court23() -> Court: return Court(id="3", name="Court 3", number=3, isIndoor=True) @pytest.fixture def court24() -> Court: return Court(id="4", name="Court 4", number=4, isIndoor=True) @pytest.fixture def sport2(court21: Court, court22: Court, court23: Court, court24: Court) -> Sport: return Sport( name="Sport 2", id=10, duration=44, price=23, players=1, courts=[court21, court22, court23, court24], ) @pytest.fixture def landing_url() -> Url: return Url( name="landing-page", path="landing.html", ) @pytest.fixture def login_url() -> Url: return Url( name="login", path="login.html", payloadTemplate="gestion-sports/login-payload.txt", ) @pytest.fixture def booking_url() -> Url: return Url( name="booking", path="booking.html", payloadTemplate="gestion-sports/booking-payload.txt", ) @pytest.fixture def user_bookings_url() -> Url: return Url( name="user-bookings", path="user_bookings.html", payloadTemplate="gestion-sports/user-bookings-payload.txt", ) @pytest.fixture def cancellation_url() -> Url: return Url( name="cancellation", path="cancel.html", payloadTemplate="gestion-sports/booking-cancellation-payload.txt", ) @pytest.fixture def tournament_sessions_url() -> Url: return Url( name="tournament-sessions", path="/tournaments_sessions.php", payloadTemplate="gestion-sports/tournament-sessions-payload.txt", ) @pytest.fixture def tournaments_list_url() -> Url: return Url( name="tournaments-list", path="/tournaments_list.html?event=", ) @pytest.fixture def booking_opening() -> BookingOpening: return BookingOpening(daysBefore=7, time="00:00") @pytest.fixture def total_bookings() -> TotalBookings: return TotalBookings(peakHours=3, offPeakHours="unlimited") @pytest.fixture def booking_platform( booking_opening: BookingOpening, total_bookings: TotalBookings, sport1: Sport, sport2: Sport, landing_url: str, login_url: str, booking_url: str, user_bookings_url: str, cancellation_url: str, tournament_sessions_url: str, tournaments_list_url: str, ) -> BookingPlatform: return BookingPlatform( id="gestion-sports", clubId=21, url="https://ptf1.com", hoursBeforeCancellation=7, bookingOpening=booking_opening, totalBookings=total_bookings, sports=[sport1, sport2], urls={ "landing-page": landing_url, "login": login_url, "booking": booking_url, "user-bookings": user_bookings_url, "cancellation": cancellation_url, "tournament-sessions": tournament_sessions_url, "tournaments-list": tournaments_list_url, }, ) @pytest.fixture def club(booking_platform: BookingPlatform) -> Club: return Club( id="super_club", name="Super Club", url="https://superclub.com", bookingPlatform=booking_platform, ) @pytest.fixture def connector(club) -> GestionSportsConnector: return GestionSportsConnector(club) @pytest.fixture def gs_services() -> GestionSportsServices: return GestionSportsServices() @pytest.fixture def user() -> User: return User(login="padel.testing@jouf.fr", password="ridicule") @pytest.fixture def booking_filter() -> BookingFilter: return BookingFilter( sport_name="Sport1", date=pendulum.parse("2024-03-21T13:30:00Z") ) @pytest.fixture def landing_response() -> str: file = RESPONSES_FOLDER / "landing-response.html" return file.read_text(encoding="utf-8") @pytest.fixture def login_success_response() -> dict: login_success_file = RESPONSES_FOLDER / "login-success.json" return json.loads(login_success_file.read_text(encoding="utf-8")) @pytest.fixture def login_failure_response() -> dict: file = RESPONSES_FOLDER / "login-failure.json" return json.loads(file.read_text(encoding="utf-8")) @pytest.fixture def booking_success_response() -> dict: file = RESPONSES_FOLDER / "booking-success.json" return json.loads(file.read_text(encoding="utf-8")) @pytest.fixture def booking_failure_response() -> dict: file = RESPONSES_FOLDER / "booking-failure.json" return json.loads(file.read_text(encoding="utf-8")) @pytest.fixture def booked_courts_response( court11: int, court12: int, court13: int, court14: int, booking_success_response: dict, booking_failure_response: dict, ) -> list[tuple[int, dict]]: court1_resp = court11.id, booking_failure_response court2_resp = court12.id, booking_failure_response court3_resp = court13.id, booking_success_response court4_resp = court14.id, booking_failure_response return [court1_resp, court2_resp, court3_resp, court4_resp] @pytest.fixture def booking_success_from_start( landing_response: str, login_success_response: str, booking_success_response: str, booking_failure_response: str, ): return [ landing_response, login_success_response, booking_failure_response, booking_success_response, booking_failure_response, booking_failure_response, ] @pytest.fixture def booking_failure_from_start( landing_response: str, login_success_response: str, booking_success_response: str, booking_failure_response: str, ): return [ landing_response, login_success_response, booking_failure_response, booking_failure_response, booking_failure_response, booking_failure_response, ] @pytest.fixture def user_bookings_get_response() -> str: file = RESPONSES_FOLDER / "user-bookings-get.html" return file.read_text(encoding="utf-8") @pytest.fixture def user_bookings_list() -> str: file = RESPONSES_FOLDER / "user-bookings-post.json" return json.loads(file.read_text(encoding="utf-8")) @pytest.fixture def user_has_ongoing_bookings_from_start( landing_response: str, login_success_response: str, user_bookings_get_response: str, user_bookings_list: str, ) -> list: return [ landing_response, login_success_response, user_bookings_get_response, user_bookings_list, ] @pytest.fixture def user_bookings_empty_list() -> list: return [] @pytest.fixture def user_has_no_ongoing_bookings_from_start( landing_response: str, login_success_response: str, user_bookings_get_response: str, user_bookings_empty_list: str, ) -> list: return [ landing_response, login_success_response, user_bookings_get_response, user_bookings_empty_list, ] @pytest.fixture def cancellation_response() -> list: file = RESPONSES_FOLDER / "cancellation-response.json" return json.loads(file.read_text(encoding="utf-8")) @pytest.fixture def cancellation_by_id_from_start( landing_response: str, login_success_response: str, user_bookings_get_response: str, cancellation_response: str, ): return [ landing_response, login_success_response, user_bookings_get_response, cancellation_response, ] @pytest.fixture def cancellation_success_from_start( landing_response: str, login_success_response: str, user_bookings_get_response: str, user_bookings_list: str, cancellation_response: str, ): return [ landing_response, login_success_response, user_bookings_get_response, user_bookings_list, cancellation_response, ] @pytest.fixture def cancellation_success_booking_filter() -> BookingFilter: return BookingFilter( sport_name="Sport1", date=pendulum.parse("2024-03-21T13:30:00Z") ) @pytest.fixture def service() -> GestionSportsServices: return GestionSportsServices() @pytest.fixture def tournament_sessions_json() -> str: file = RESPONSES_FOLDER / "tournament-sessions.json" return file.read_text(encoding="utf-8") @pytest.fixture def tournaments_html() -> str: file = RESPONSES_FOLDER / "tournaments.html" return file.read_text(encoding="utf-8") @pytest.fixture def full_tournaments_responses( landing_response: str, login_success_response: str, tournament_sessions_json: str, tournaments_html: str, ) -> list[str]: return [ landing_response, login_success_response, tournament_sessions_json, tournaments_html, ]