From 59e2271c1bc85b2bc93d0147c1542c1d22a8dd7d Mon Sep 17 00:00:00 2001 From: stanislas Date: Wed, 21 Feb 2024 23:28:08 +0100 Subject: [PATCH] refactored code to place the booking specific actions inside a gestion-sports element --- .../gestion_sports_operations.py | 28 +++++++++---------- .../test_gestion_sports_operations.py | 3 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/resa_padel/gestion_sports/gestion_sports_operations.py b/resa_padel/gestion_sports/gestion_sports_operations.py index 24a6940..de10d9b 100644 --- a/resa_padel/gestion_sports/gestion_sports_operations.py +++ b/resa_padel/gestion_sports/gestion_sports_operations.py @@ -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: diff --git a/tests/gestion_sports/test_gestion_sports_operations.py b/tests/gestion_sports/test_gestion_sports_operations.py index 073be9c..5fc67c8 100644 --- a/tests/gestion_sports/test_gestion_sports_operations.py +++ b/tests/gestion_sports/test_gestion_sports_operations.py @@ -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)