Added a service that can get all current tournaments list
This commit is contained in:
parent
e6023e0687
commit
3d0bd47079
26 changed files with 4305 additions and 204 deletions
|
@ -3,7 +3,7 @@ from pathlib import Path
|
|||
|
||||
import pendulum
|
||||
import pytest
|
||||
from connectors import GestionSportsConnector
|
||||
from gestion_sport_connector import GestionSportsConnector
|
||||
from gestion_sports_services import GestionSportsServices
|
||||
from models import (
|
||||
BookingFilter,
|
||||
|
@ -43,7 +43,7 @@ def court14() -> Court:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def sport1(court11, court12, court13, court14) -> Sport:
|
||||
def sport1(court11: Court, court12: Court, court13: Court, court14: Court) -> Sport:
|
||||
return Sport(
|
||||
name="Sport1",
|
||||
id=8,
|
||||
|
@ -75,7 +75,7 @@ def court24() -> Court:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def sport2(court21, court22, court23, court24) -> Sport:
|
||||
def sport2(court21: Court, court22: Court, court23: Court, court24: Court) -> Sport:
|
||||
return Sport(
|
||||
name="Sport 2",
|
||||
id=10,
|
||||
|
@ -130,9 +130,26 @@ def cancellation_url() -> Url:
|
|||
)
|
||||
|
||||
|
||||
@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=10, time="03:27")
|
||||
return BookingOpening(daysBefore=7, time="00:00")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -142,15 +159,17 @@ def total_bookings() -> TotalBookings:
|
|||
|
||||
@pytest.fixture
|
||||
def booking_platform(
|
||||
booking_opening,
|
||||
total_bookings,
|
||||
sport1,
|
||||
sport2,
|
||||
landing_url,
|
||||
login_url,
|
||||
booking_url,
|
||||
user_bookings_url,
|
||||
cancellation_url,
|
||||
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",
|
||||
|
@ -166,12 +185,14 @@ def booking_platform(
|
|||
"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) -> Club:
|
||||
def club(booking_platform: BookingPlatform) -> Club:
|
||||
return Club(
|
||||
id="super_club",
|
||||
name="Super Club",
|
||||
|
@ -204,42 +225,42 @@ def booking_filter() -> BookingFilter:
|
|||
|
||||
@pytest.fixture
|
||||
def landing_response() -> str:
|
||||
landing_response_file = RESPONSES_FOLDER / "landing_response.html"
|
||||
return landing_response_file.read_text(encoding="utf-8")
|
||||
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"
|
||||
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"))
|
||||
file = RESPONSES_FOLDER / "login-failure.json"
|
||||
return json.loads(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"))
|
||||
file = RESPONSES_FOLDER / "booking-success.json"
|
||||
return json.loads(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"))
|
||||
file = RESPONSES_FOLDER / "booking-failure.json"
|
||||
return json.loads(file.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def booked_courts_response(
|
||||
court11,
|
||||
court12,
|
||||
court13,
|
||||
court14,
|
||||
booking_success_response,
|
||||
booking_failure_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
|
||||
|
@ -250,10 +271,10 @@ def booked_courts_response(
|
|||
|
||||
@pytest.fixture
|
||||
def booking_success_from_start(
|
||||
landing_response,
|
||||
login_success_response,
|
||||
booking_success_response,
|
||||
booking_failure_response,
|
||||
landing_response: str,
|
||||
login_success_response: str,
|
||||
booking_success_response: str,
|
||||
booking_failure_response: str,
|
||||
):
|
||||
return [
|
||||
landing_response,
|
||||
|
@ -267,10 +288,10 @@ def booking_success_from_start(
|
|||
|
||||
@pytest.fixture
|
||||
def booking_failure_from_start(
|
||||
landing_response,
|
||||
login_success_response,
|
||||
booking_success_response,
|
||||
booking_failure_response,
|
||||
landing_response: str,
|
||||
login_success_response: str,
|
||||
booking_success_response: str,
|
||||
booking_failure_response: str,
|
||||
):
|
||||
return [
|
||||
landing_response,
|
||||
|
@ -284,22 +305,22 @@ def booking_failure_from_start(
|
|||
|
||||
@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")
|
||||
file = RESPONSES_FOLDER / "user-bookings-get.html"
|
||||
return 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"))
|
||||
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,
|
||||
login_success_response,
|
||||
user_bookings_get_response,
|
||||
user_bookings_list,
|
||||
landing_response: str,
|
||||
login_success_response: str,
|
||||
user_bookings_get_response: str,
|
||||
user_bookings_list: str,
|
||||
) -> list:
|
||||
return [
|
||||
landing_response,
|
||||
|
@ -316,10 +337,10 @@ def user_bookings_empty_list() -> list:
|
|||
|
||||
@pytest.fixture
|
||||
def user_has_no_ongoing_bookings_from_start(
|
||||
landing_response,
|
||||
login_success_response,
|
||||
user_bookings_get_response,
|
||||
user_bookings_empty_list,
|
||||
landing_response: str,
|
||||
login_success_response: str,
|
||||
user_bookings_get_response: str,
|
||||
user_bookings_empty_list: str,
|
||||
) -> list:
|
||||
return [
|
||||
landing_response,
|
||||
|
@ -331,16 +352,16 @@ def user_has_no_ongoing_bookings_from_start(
|
|||
|
||||
@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"))
|
||||
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,
|
||||
login_success_response,
|
||||
user_bookings_get_response,
|
||||
cancellation_response,
|
||||
landing_response: str,
|
||||
login_success_response: str,
|
||||
user_bookings_get_response: str,
|
||||
cancellation_response: str,
|
||||
):
|
||||
return [
|
||||
landing_response,
|
||||
|
@ -352,11 +373,11 @@ def cancellation_by_id_from_start(
|
|||
|
||||
@pytest.fixture
|
||||
def cancellation_success_from_start(
|
||||
landing_response,
|
||||
login_success_response,
|
||||
user_bookings_get_response,
|
||||
user_bookings_list,
|
||||
cancellation_response,
|
||||
landing_response: str,
|
||||
login_success_response: str,
|
||||
user_bookings_get_response: str,
|
||||
user_bookings_list: str,
|
||||
cancellation_response: str,
|
||||
):
|
||||
return [
|
||||
landing_response,
|
||||
|
@ -377,3 +398,30 @@ def cancellation_success_booking_filter() -> BookingFilter:
|
|||
@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,
|
||||
]
|
||||
|
|
|
@ -1,31 +1,24 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from aiohttp import ClientSession
|
||||
from connectors import GestionSportsConnector
|
||||
from gestion_sport_connector import GestionSportsConnector
|
||||
|
||||
from tests.unit_tests import responses
|
||||
|
||||
|
||||
def test_urls(connector, club):
|
||||
base_url = club.booking_platform.url
|
||||
relative_urls = club.booking_platform.urls
|
||||
base_url = "https://ptf1.com"
|
||||
|
||||
relative_landing_url = relative_urls.get("landing-page").path
|
||||
assert connector.landing_url == f"{base_url}/{relative_landing_url}"
|
||||
|
||||
relative_login_url = relative_urls.get("login").path
|
||||
assert connector.login_url == f"{base_url}/{relative_login_url}"
|
||||
|
||||
relative_booking_url = relative_urls.get("booking").path
|
||||
assert connector.booking_url == f"{base_url}/{relative_booking_url}"
|
||||
|
||||
relative_user_bookings_url = relative_urls.get("user-bookings").path
|
||||
assert connector.user_bookings_url == f"{base_url}/{relative_user_bookings_url}"
|
||||
|
||||
relative_cancel_url = relative_urls.get("cancellation").path
|
||||
assert connector.booking_cancellation_url == f"{base_url}/{relative_cancel_url}"
|
||||
assert connector.landing_url == f"{base_url}/landing.html"
|
||||
assert connector.login_url == f"{base_url}/login.html"
|
||||
assert connector.booking_url == f"{base_url}/booking.html"
|
||||
assert connector.user_bookings_url == f"{base_url}/user_bookings.html"
|
||||
assert connector.booking_cancellation_url == f"{base_url}/cancel.html"
|
||||
assert connector.tournaments_sessions_url == f"{base_url}/tournaments_sessions.php"
|
||||
assert connector.tournaments_list_url == f"{base_url}/tournaments_list.html?event="
|
||||
|
||||
|
||||
@patch("config.get_resources_folder")
|
||||
|
@ -34,19 +27,27 @@ def test_urls_payload_templates(mock_resources, club):
|
|||
mock_resources.return_value = path_to_resources
|
||||
|
||||
connector = GestionSportsConnector(club)
|
||||
relative_urls = club.booking_platform.urls
|
||||
|
||||
login_payload = relative_urls.get("login").payload_template
|
||||
assert connector.login_template == path_to_resources / login_payload
|
||||
|
||||
booking_payload = relative_urls.get("booking").payload_template
|
||||
assert connector.booking_template == path_to_resources / booking_payload
|
||||
|
||||
user_bookings_payload = relative_urls.get("user-bookings").payload_template
|
||||
assert connector.user_bookings_template == path_to_resources / user_bookings_payload
|
||||
|
||||
cancel_payload = relative_urls.get("cancellation").payload_template
|
||||
assert connector.booking_cancel_template == path_to_resources / cancel_payload
|
||||
assert (
|
||||
connector.login_template
|
||||
== path_to_resources / "gestion-sports/login-payload.txt"
|
||||
)
|
||||
assert (
|
||||
connector.booking_template
|
||||
== path_to_resources / "gestion-sports/booking-payload.txt"
|
||||
)
|
||||
assert (
|
||||
connector.user_bookings_template
|
||||
== path_to_resources / "gestion-sports/user-bookings-payload.txt"
|
||||
)
|
||||
assert (
|
||||
connector.booking_cancel_template
|
||||
== path_to_resources / "gestion-sports/booking-cancellation-payload.txt"
|
||||
)
|
||||
assert (
|
||||
connector.tournaments_sessions_template
|
||||
== path_to_resources / "gestion-sports/tournament-sessions-payload.txt"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -143,3 +144,35 @@ async def test_cancel_booking_success(
|
|||
)
|
||||
|
||||
assert await response.json() == cancellation_success_from_start[4]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tournament_sessions(
|
||||
aioresponses, connector, user, tournament_sessions_json
|
||||
):
|
||||
responses.set_tournaments_sessions_response(
|
||||
aioresponses, connector, tournament_sessions_json
|
||||
)
|
||||
async with ClientSession() as session:
|
||||
response = await connector.send_tournaments_sessions_request(session)
|
||||
|
||||
assert response.status == 200
|
||||
|
||||
all_sessions = json.loads(await response.text())
|
||||
sessions = all_sessions.get("Inscription tournois:school-outline")
|
||||
assert len(sessions) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_tournaments_request(
|
||||
aioresponses, connector, user, tournaments_html
|
||||
):
|
||||
tournament_session_id = "255"
|
||||
responses.set_tournaments_list_response(
|
||||
aioresponses, connector, tournament_session_id, tournaments_html
|
||||
)
|
||||
async with ClientSession() as session:
|
||||
response = await connector.send_tournaments_request(
|
||||
session, tournament_session_id
|
||||
)
|
||||
assert "<span class='nb_place_libre'>Complet</span>" in await response.text()
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
import pendulum
|
||||
import pytest
|
||||
from gestion_sports_services import GestionSportsServices
|
||||
from models import BookingFilter, BookingOpening
|
||||
|
||||
from tests.unit_tests import responses
|
||||
|
||||
|
@ -108,3 +112,65 @@ async def test_cancel_booking_id(
|
|||
)
|
||||
|
||||
await gs_services.cancel_booking_id(user, club, 65464)
|
||||
|
||||
|
||||
@patch("pendulum.now")
|
||||
def test_wait_until_booking_time(mock_now, club, user):
|
||||
booking_filter = BookingFilter(
|
||||
sport_name="Sport1", date=pendulum.parse("2024-03-21T13:30:00+01:00")
|
||||
)
|
||||
|
||||
booking_datetime = pendulum.parse("2024-03-14T00:00:00+01:00")
|
||||
|
||||
seconds = [
|
||||
booking_datetime.subtract(seconds=3),
|
||||
booking_datetime.subtract(seconds=2),
|
||||
booking_datetime.subtract(seconds=1),
|
||||
booking_datetime,
|
||||
booking_datetime.add(microseconds=1),
|
||||
booking_datetime.add(microseconds=2),
|
||||
]
|
||||
mock_now.side_effect = seconds
|
||||
|
||||
booking_opening = club.booking_platform.booking_opening
|
||||
|
||||
GestionSportsServices.wait_until_booking_time(booking_filter, booking_opening)
|
||||
|
||||
assert pendulum.now() == booking_datetime.add(microseconds=1)
|
||||
|
||||
|
||||
def test_build_booking_time():
|
||||
booking_filter = BookingFilter(
|
||||
sport_name="Sport1", date=pendulum.parse("2024-03-21T13:30:00+01:00")
|
||||
)
|
||||
booking_opening = BookingOpening(daysBefore=7, time="00:00")
|
||||
|
||||
booking_time = GestionSportsServices.build_booking_datetime(
|
||||
booking_filter, booking_opening
|
||||
)
|
||||
|
||||
assert booking_time == pendulum.parse("2024-03-13T23:00:00Z")
|
||||
|
||||
|
||||
def test_retrieve_tournament_id(tournament_sessions_json):
|
||||
session_id = GestionSportsServices.retrieve_tournament_session(
|
||||
tournament_sessions_json
|
||||
)
|
||||
|
||||
assert session_id == "1174"
|
||||
|
||||
|
||||
def test_retrieve_tournaments(tournaments_html):
|
||||
tournaments = GestionSportsServices.retrieve_tournaments(tournaments_html)
|
||||
assert len(tournaments) == 14
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_all_tournaments(
|
||||
aioresponses, user, connector, club, full_tournaments_responses
|
||||
):
|
||||
responses.set_full_tournaments_requests(
|
||||
aioresponses, connector, full_tournaments_responses, 1174
|
||||
)
|
||||
tournaments = await GestionSportsServices.get_all_tournaments(user, club)
|
||||
assert len(tournaments) == 14
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue