refactored code to place the booking specific actions inside a gestion-sports element
This commit is contained in:
parent
d0a0072b6d
commit
26670bfe34
5 changed files with 251 additions and 215 deletions
81
tests/gestion_sports/test_gestion_sports_operations.py
Normal file
81
tests/gestion_sports/test_gestion_sports_operations.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
import pendulum
|
||||
import pytest
|
||||
from aioresponses import aioresponses
|
||||
from gestion_sports.gestion_sports_operations import GestionSportsOperations
|
||||
from models import BookingFilter, Club, User
|
||||
|
||||
from tests import fixtures, utils
|
||||
from tests.fixtures import (
|
||||
a_booking_failure_response,
|
||||
a_booking_filter,
|
||||
a_booking_success_response,
|
||||
a_club,
|
||||
a_user,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("pendulum.now")
|
||||
async def test_booking(
|
||||
mock_now,
|
||||
a_booking_success_response: str,
|
||||
a_booking_failure_response: str,
|
||||
a_user: User,
|
||||
a_club: Club,
|
||||
a_booking_filter: BookingFilter,
|
||||
):
|
||||
"""
|
||||
Test a single court booking without reading the conf from environment variables
|
||||
|
||||
:param mock_now: the pendulum.now() mock
|
||||
:param a_booking_success_response: the success json response
|
||||
:param a_booking_failure_response: the failure json response
|
||||
:param a_user: a test user
|
||||
:param a_club:a test club
|
||||
:param a_booking_filter: a test booking filter
|
||||
"""
|
||||
booking_datetime = utils.retrieve_booking_datetime(a_booking_filter, a_club)
|
||||
mock_now.side_effect = [booking_datetime]
|
||||
|
||||
# mock connection to the booking platform
|
||||
with aioresponses() as aio_mock:
|
||||
utils.mock_rest_api_from_connection_to_booking(
|
||||
aio_mock,
|
||||
fixtures.url,
|
||||
a_booking_failure_response,
|
||||
a_booking_success_response,
|
||||
)
|
||||
|
||||
async with GestionSportsOperations(a_club) as gs_operations:
|
||||
court_booked = await gs_operations.book(a_user, a_booking_filter)
|
||||
assert court_booked == a_club.courts_ids[1]
|
||||
|
||||
|
||||
@patch("pendulum.now")
|
||||
def test_wait_until_booking_time(
|
||||
mock_now, a_club: Club, a_booking_filter: BookingFilter
|
||||
):
|
||||
"""
|
||||
Test the function that waits until the booking can be performed
|
||||
|
||||
:param mock_now: the pendulum.now() mock
|
||||
:param a_club: a club
|
||||
:param a_booking_filter: a booking filter
|
||||
"""
|
||||
booking_datetime = utils.retrieve_booking_datetime(a_booking_filter, a_club)
|
||||
|
||||
seconds = [
|
||||
booking_datetime.subtract(seconds=3),
|
||||
booking_datetime.subtract(seconds=2),
|
||||
booking_datetime.subtract(seconds=1),
|
||||
booking_datetime,
|
||||
booking_datetime.add(microseconds=1),
|
||||
booking_datetime.add(microseconds=2),
|
||||
]
|
||||
mock_now.side_effect = seconds
|
||||
|
||||
GestionSportsOperations.wait_until_booking_time(a_club, a_booking_filter)
|
||||
|
||||
assert pendulum.now() == booking_datetime.add(microseconds=1)
|
Loading…
Add table
Add a link
Reference in a new issue