import asyncio import pendulum from aioresponses import aioresponses from resa_padel import booking from resa_padel.models import BookingFilter, User from tests.fixtures import (a_booking_failure_response, a_booking_success_response) login = "user" password = "password" club_id = "98" court_id = "11" # FIXME # check that called are passed to the given urls # check made with cookies, but at the current time, cookies from the response are # not set in the session. Why ? I don't know.... def test_booking_does_the_rights_calls( a_booking_success_response, a_booking_failure_response ): # mock connection to the booking platform platform_url = "https://some.url" connection_url = platform_url + "/connexion.php" login_url = connection_url booking_url = platform_url + "/membre/reservation.html" loop = asyncio.get_event_loop() with aioresponses() as aio_mock: aio_mock.get( connection_url, status=200, headers={"Set-Cookie": f"connection_called=True; Domain={platform_url}"}, ) aio_mock.post( login_url, status=200, headers={"Set-Cookie": f"login_called=True; Domain={platform_url}"}, ) aio_mock.post( booking_url, status=200, headers={"Set-Cookie": f"booking_called=True; Domain={platform_url}"}, body=a_booking_failure_response, ) aio_mock.post( booking_url, status=200, headers={"Set-Cookie": f"booking_called=True; Domain={platform_url}"}, body=a_booking_success_response, ) user = User(login=login, password=password, club_id=club_id) booking_filter = BookingFilter( court_ids=[607, 606], sport_id=444, date=pendulum.now().add(days=6) ) loop.run_until_complete(booking.book(platform_url, user, booking_filter)) # cookies = session.cookie_jar.filter_cookies(platform_url) # assert cookies.get("connection_called") == "True" # assert cookies.get("login_called") == "True" # assert cookies.get("booking_called") == "True"