refactored code to place the booking specific actions inside a gestion-sports element
This commit is contained in:
parent
26670bfe34
commit
59e2271c1b
2 changed files with 16 additions and 15 deletions
|
@ -33,22 +33,22 @@ class GestionSportsOperations:
|
||||||
self.wait_until_booking_time(self.club, booking_filter)
|
self.wait_until_booking_time(self.club, booking_filter)
|
||||||
return await self.platform.book(booking_filter, self.club)
|
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
|
def wait_until_booking_time(club: Club, booking_filter: BookingFilter):
|
||||||
:param booking_filter: the booking information
|
"""
|
||||||
"""
|
Wait until the booking is open.
|
||||||
LOGGER.info("Waiting booking time")
|
The booking filter contains the date and time of the booking.
|
||||||
booking_datetime = build_booking_datetime(booking_filter, club)
|
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()
|
now = pendulum.now()
|
||||||
while now < booking_datetime:
|
|
||||||
time.sleep(1)
|
|
||||||
now = pendulum.now()
|
|
||||||
|
|
||||||
|
|
||||||
def build_booking_datetime(booking_filter: BookingFilter, club: Club) -> DateTime:
|
def build_booking_datetime(booking_filter: BookingFilter, club: Club) -> DateTime:
|
||||||
|
|
|
@ -3,6 +3,7 @@ from unittest.mock import patch
|
||||||
import pendulum
|
import pendulum
|
||||||
import pytest
|
import pytest
|
||||||
from aioresponses import aioresponses
|
from aioresponses import aioresponses
|
||||||
|
from gestion_sports import gestion_sports_operations
|
||||||
from gestion_sports.gestion_sports_operations import GestionSportsOperations
|
from gestion_sports.gestion_sports_operations import GestionSportsOperations
|
||||||
from models import BookingFilter, Club, User
|
from models import BookingFilter, Club, User
|
||||||
|
|
||||||
|
@ -76,6 +77,6 @@ def test_wait_until_booking_time(
|
||||||
]
|
]
|
||||||
mock_now.side_effect = seconds
|
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)
|
assert pendulum.now() == booking_datetime.add(microseconds=1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue