Added a service that can get all current tournaments list

This commit is contained in:
Stanislas Jouffroy 2024-03-23 11:56:31 +01:00
parent e6023e0687
commit 3d0bd47079
26 changed files with 4305 additions and 204 deletions

View file

@ -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