refactored code to place the booking specific actions inside a gestion-sports element

This commit is contained in:
Stanislas Jouffroy 2024-02-21 23:28:08 +01:00
parent 26670bfe34
commit 59e2271c1b
2 changed files with 16 additions and 15 deletions

View file

@ -33,22 +33,22 @@ class GestionSportsOperations:
self.wait_until_booking_time(self.club, booking_filter)
return await self.platform.book(booking_filter, self.club)
@staticmethod
def wait_until_booking_time(club: Club, booking_filter: BookingFilter):
"""
Wait until the booking is open.
The booking filter contains the date and time of the booking.
The club has the information about when the booking is open for that date.
:param club: the club where to book a court
:param booking_filter: the booking information
"""
LOGGER.info("Waiting booking time")
booking_datetime = build_booking_datetime(booking_filter, club)
def wait_until_booking_time(club: Club, booking_filter: BookingFilter):
"""
Wait until the booking is open.
The booking filter contains the date and time of the booking.
The club has the information about when the booking is open for that date.
:param club: the club where to book a court
:param booking_filter: the booking information
"""
LOGGER.info("Waiting booking time")
booking_datetime = build_booking_datetime(booking_filter, club)
now = pendulum.now()
while now < booking_datetime:
time.sleep(1)
now = pendulum.now()
while now < booking_datetime:
time.sleep(1)
now = pendulum.now()
def build_booking_datetime(booking_filter: BookingFilter, club: Club) -> DateTime:

View file

@ -3,6 +3,7 @@ from unittest.mock import patch
import pendulum
import pytest
from aioresponses import aioresponses
from gestion_sports import gestion_sports_operations
from gestion_sports.gestion_sports_operations import GestionSportsOperations
from models import BookingFilter, Club, User
@ -76,6 +77,6 @@ def test_wait_until_booking_time(
]
mock_now.side_effect = seconds
GestionSportsOperations.wait_until_booking_time(a_club, a_booking_filter)
gestion_sports_operations.wait_until_booking_time(a_club, a_booking_filter)
assert pendulum.now() == booking_datetime.add(microseconds=1)