284 lines
6.7 KiB
Python
284 lines
6.7 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
import pendulum
|
|
import pytest
|
|
from connectors import GestionSportsConnector
|
|
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"
|
|
|
|
court11 = Court(id="1", name="Court 1", number=1, isIndoor=True)
|
|
court12 = Court(id="2", name="Court 2", number=2, isIndoor=False)
|
|
court13 = Court(id="3", name="Court 3", number=3, isIndoor=True)
|
|
court14 = Court(id="4", name="Court 4", number=4, isIndoor=True)
|
|
|
|
sport1 = Sport(
|
|
name="Sport1",
|
|
id=8,
|
|
duration=99,
|
|
price=54,
|
|
players=3,
|
|
courts=[court11, court12, court13, court14],
|
|
)
|
|
|
|
court21 = Court(id="1", name="Court 1", number=1, isIndoor=False)
|
|
court22 = Court(id="2", name="Court 2", number=2, isIndoor=True)
|
|
court23 = Court(id="3", name="Court 3", number=3, isIndoor=True)
|
|
court24 = Court(id="4", name="Court 4", number=4, isIndoor=True)
|
|
|
|
sport2 = Sport(
|
|
name="Sport 2",
|
|
id=10,
|
|
duration=44,
|
|
price=23,
|
|
players=1,
|
|
courts=[court21, court22, court23, court24],
|
|
)
|
|
|
|
landing_url = Url(
|
|
name="landing-page",
|
|
path="landing.html",
|
|
)
|
|
|
|
login_url = Url(
|
|
name="login",
|
|
path="login.html",
|
|
payloadTemplate="gestion-sports/login-payload.txt",
|
|
)
|
|
|
|
booking_url = Url(
|
|
name="booking",
|
|
path="booking.html",
|
|
payloadTemplate="gestion-sports/booking-payload.txt",
|
|
)
|
|
|
|
user_bookings_url = Url(
|
|
name="user-bookings",
|
|
path="user_bookings.html",
|
|
payloadTemplate="gestion-sports/user-bookings-payload.txt",
|
|
)
|
|
|
|
cancellation_url = Url(
|
|
name="cancellation",
|
|
path="cancel.html",
|
|
payloadTemplate="gestion-sports/booking-cancellation-payload.txt",
|
|
)
|
|
|
|
booking_opening = BookingOpening(daysBefore=10, time="03:27")
|
|
|
|
total_bookings = TotalBookings(peakHours=3, offPeakHours="unlimited")
|
|
|
|
booking_platform = 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,
|
|
},
|
|
)
|
|
|
|
club = Club(
|
|
id="super_club",
|
|
name="Super Club",
|
|
url="https://superclub.com",
|
|
bookingPlatform=booking_platform,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def a_club() -> Club:
|
|
return club
|
|
|
|
|
|
@pytest.fixture
|
|
def connector() -> GestionSportsConnector:
|
|
return GestionSportsConnector(club)
|
|
|
|
|
|
@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:
|
|
landing_response_file = RESPONSES_FOLDER / "landing_response.html"
|
|
return landing_response_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:
|
|
login_failure_file = RESPONSES_FOLDER / "login_failure.json"
|
|
return json.loads(login_failure_file.read_text(encoding="utf-8"))
|
|
|
|
|
|
@pytest.fixture
|
|
def booking_success_response() -> dict:
|
|
booking_success_file = RESPONSES_FOLDER / "booking_success.json"
|
|
return json.loads(booking_success_file.read_text(encoding="utf-8"))
|
|
|
|
|
|
@pytest.fixture
|
|
def booking_failure_response() -> dict:
|
|
booking_failure_file = RESPONSES_FOLDER / "booking_failure.json"
|
|
return json.loads(booking_failure_file.read_text(encoding="utf-8"))
|
|
|
|
|
|
@pytest.fixture
|
|
def booking_success_from_start(
|
|
landing_response,
|
|
login_success_response,
|
|
booking_success_response,
|
|
booking_failure_response,
|
|
):
|
|
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,
|
|
login_success_response,
|
|
booking_success_response,
|
|
booking_failure_response,
|
|
):
|
|
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:
|
|
user_bookings_file = RESPONSES_FOLDER / "user_bookings_get.html"
|
|
return user_bookings_file.read_text(encoding="utf-8")
|
|
|
|
|
|
@pytest.fixture
|
|
def user_bookings_list() -> list:
|
|
user_bookings_file = RESPONSES_FOLDER / "user_bookings_post.json"
|
|
return json.loads(user_bookings_file.read_text(encoding="utf-8"))
|
|
|
|
|
|
@pytest.fixture
|
|
def user_has_ongoing_bookings_from_start(
|
|
landing_response,
|
|
login_success_response,
|
|
user_bookings_get_response,
|
|
user_bookings_list,
|
|
) -> 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,
|
|
login_success_response,
|
|
user_bookings_get_response,
|
|
user_bookings_empty_list,
|
|
) -> list:
|
|
return [
|
|
landing_response,
|
|
login_success_response,
|
|
user_bookings_get_response,
|
|
user_bookings_empty_list,
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def cancellation_response() -> list:
|
|
cancellation_response_file = RESPONSES_FOLDER / "cancellation_response.json"
|
|
return json.loads(cancellation_response_file.read_text(encoding="utf-8"))
|
|
|
|
|
|
@pytest.fixture
|
|
def cancellation_by_id_from_start(
|
|
landing_response,
|
|
login_success_response,
|
|
user_bookings_get_response,
|
|
cancellation_response,
|
|
):
|
|
return [
|
|
landing_response,
|
|
login_success_response,
|
|
user_bookings_get_response,
|
|
cancellation_response,
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def cancellation_success_from_start(
|
|
landing_response,
|
|
login_success_response,
|
|
user_bookings_get_response,
|
|
user_bookings_list,
|
|
cancellation_response,
|
|
):
|
|
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")
|
|
)
|