From 552db2aa8a33168a9927d703939823d9e7653235 Mon Sep 17 00:00:00 2001 From: stanislas Date: Wed, 21 Feb 2024 23:49:33 +0100 Subject: [PATCH] refactored code to place the booking specific actions inside a gestion-sports element --- resa_padel/booking.py | 4 ++-- ...ts_operations.py => gestion_sports_platform.py} | 14 +++++++------- .../test_gestion_sports_operations.py | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) rename resa_padel/gestion_sports/{gestion_sports_operations.py => gestion_sports_platform.py} (83%) diff --git a/resa_padel/booking.py b/resa_padel/booking.py index 4b04dff..c67b9de 100644 --- a/resa_padel/booking.py +++ b/resa_padel/booking.py @@ -2,7 +2,7 @@ import asyncio import logging import config -from gestion_sports.gestion_sports_operations import GestionSportsOperations +from gestion_sports.gestion_sports_platform import GestionSportsPlatform from models import BookingFilter, Club, User LOGGER = logging.getLogger(__name__) @@ -17,7 +17,7 @@ async def book(club: Club, user: User, booking_filter: BookingFilter) -> int | N :param booking_filter: the information related to the booking :return: the id of the booked court, or None if no court was booked """ - async with GestionSportsOperations(club) as platform: + async with GestionSportsPlatform(club) as platform: return await platform.book(user, booking_filter) diff --git a/resa_padel/gestion_sports/gestion_sports_operations.py b/resa_padel/gestion_sports/gestion_sports_platform.py similarity index 83% rename from resa_padel/gestion_sports/gestion_sports_operations.py rename to resa_padel/gestion_sports/gestion_sports_platform.py index 1c06881..e76cc3b 100644 --- a/resa_padel/gestion_sports/gestion_sports_operations.py +++ b/resa_padel/gestion_sports/gestion_sports_platform.py @@ -10,28 +10,28 @@ from pendulum import DateTime LOGGER = logging.getLogger(__name__) -class GestionSportsOperations: +class GestionSportsPlatform: def __init__(self, club: Club): - self.platform: GestionSportsConnector | None = None + self.connector: GestionSportsConnector | None = None self.club: Club = club self.session: ClientSession | None = None async def __aenter__(self): self.session = ClientSession() - self.platform = GestionSportsConnector(self.session, self.club.url) + self.connector = GestionSportsConnector(self.session, self.club.url) return self async def __aexit__(self, exc_type, exc_val, exc_tb): await self.session.close() async def book(self, user: User, booking_filter: BookingFilter) -> int | None: - if self.platform is None or user is None or booking_filter is None: + if self.connector is None or user is None or booking_filter is None: return None - await self.platform.land() - await self.platform.login(user, self.club) + await self.connector.land() + await self.connector.login(user, self.club) wait_until_booking_time(self.club, booking_filter) - return await self.platform.book(booking_filter, self.club) + return await self.connector.book(booking_filter, self.club) def wait_until_booking_time(club: Club, booking_filter: BookingFilter): diff --git a/tests/gestion_sports/test_gestion_sports_operations.py b/tests/gestion_sports/test_gestion_sports_operations.py index 5fc67c8..ff1e086 100644 --- a/tests/gestion_sports/test_gestion_sports_operations.py +++ b/tests/gestion_sports/test_gestion_sports_operations.py @@ -3,8 +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 gestion_sports.gestion_sports_platform import GestionSportsPlatform from models import BookingFilter, Club, User from tests import fixtures, utils @@ -49,7 +48,7 @@ async def test_booking( a_booking_success_response, ) - async with GestionSportsOperations(a_club) as gs_operations: + async with GestionSportsPlatform(a_club) as gs_operations: court_booked = await gs_operations.book(a_user, a_booking_filter) assert court_booked == a_club.courts_ids[1]