refactored code to place the booking specific actions inside a gestion-sports element
This commit is contained in:
parent
1ec148e866
commit
552db2aa8a
3 changed files with 11 additions and 12 deletions
|
@ -2,7 +2,7 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from gestion_sports.gestion_sports_operations import GestionSportsOperations
|
from gestion_sports.gestion_sports_platform import GestionSportsPlatform
|
||||||
from models import BookingFilter, Club, User
|
from models import BookingFilter, Club, User
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
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
|
:param booking_filter: the information related to the booking
|
||||||
:return: the id of the booked court, or None if no court was booked
|
: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)
|
return await platform.book(user, booking_filter)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,28 +10,28 @@ from pendulum import DateTime
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GestionSportsOperations:
|
class GestionSportsPlatform:
|
||||||
def __init__(self, club: Club):
|
def __init__(self, club: Club):
|
||||||
self.platform: GestionSportsConnector | None = None
|
self.connector: GestionSportsConnector | None = None
|
||||||
self.club: Club = club
|
self.club: Club = club
|
||||||
self.session: ClientSession | None = None
|
self.session: ClientSession | None = None
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
self.session = ClientSession()
|
self.session = ClientSession()
|
||||||
self.platform = GestionSportsConnector(self.session, self.club.url)
|
self.connector = GestionSportsConnector(self.session, self.club.url)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||||
await self.session.close()
|
await self.session.close()
|
||||||
|
|
||||||
async def book(self, user: User, booking_filter: BookingFilter) -> int | None:
|
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
|
return None
|
||||||
|
|
||||||
await self.platform.land()
|
await self.connector.land()
|
||||||
await self.platform.login(user, self.club)
|
await self.connector.login(user, self.club)
|
||||||
wait_until_booking_time(self.club, booking_filter)
|
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):
|
def wait_until_booking_time(club: Club, booking_filter: BookingFilter):
|
|
@ -3,8 +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_platform import GestionSportsPlatform
|
||||||
from gestion_sports.gestion_sports_operations import GestionSportsOperations
|
|
||||||
from models import BookingFilter, Club, User
|
from models import BookingFilter, Club, User
|
||||||
|
|
||||||
from tests import fixtures, utils
|
from tests import fixtures, utils
|
||||||
|
@ -49,7 +48,7 @@ async def test_booking(
|
||||||
a_booking_success_response,
|
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)
|
court_booked = await gs_operations.book(a_user, a_booking_filter)
|
||||||
assert court_booked == a_club.courts_ids[1]
|
assert court_booked == a_club.courts_ids[1]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue