Added docstrings

This commit is contained in:
Stanislas Jouffroy 2024-02-18 09:16:11 +01:00
parent 5434a74d0f
commit ccd019eb4c
4 changed files with 174 additions and 21 deletions

View file

@ -2,6 +2,7 @@ import pytest
from aiohttp import ClientSession
from yarl import URL
from models import BookingFilter, Club, User
from resa_padel.gestion_sports.gestion_sports_connector import GestionSportsConnector
from tests.fixtures import (
a_booking_failure_response,
@ -16,13 +17,16 @@ tpc_url = "https://toulousepadelclub.gestion-sports.com"
@pytest.mark.asyncio
async def test_should_connect_to_gestion_sports_website():
async def test_should_reach_landing_page_to_gestion_sports_website() -> None:
"""
Test that landing page is reached
"""
async with ClientSession() as session:
cookies = session.cookie_jar.filter_cookies(URL(tpc_url))
assert cookies.get("PHPSESSID") is None
gs_connector = GestionSportsConnector(session, tpc_url)
response = await gs_connector.connect()
response = await gs_connector.land()
assert response.status == 200
assert response.request_info.method == "GET"
@ -35,10 +39,18 @@ async def test_should_connect_to_gestion_sports_website():
@pytest.mark.asyncio
async def test_should_login_to_gestion_sports_website(a_user, a_club):
async def test_should_login_to_gestion_sports_website(
a_user: User, a_club: Club
) -> None:
"""
Test that a user can log in after reaching the landing page
:param a_user: the user that wants to book a court
:param a_club: the club information
"""
async with ClientSession() as session:
gs_connector = GestionSportsConnector(session, tpc_url)
await gs_connector.connect()
await gs_connector.land()
response = await gs_connector.login(a_user, a_club)
@ -53,10 +65,19 @@ async def test_should_login_to_gestion_sports_website(a_user, a_club):
@pytest.mark.asyncio
async def test_booking_url_should_be_reachable(a_user, a_booking_filter, a_club):
async def test_booking_url_should_be_reachable(
a_user: User, a_booking_filter: BookingFilter, a_club: Club
) -> None:
"""
Test that a user can log in the booking platform and book a court
:param a_user: the user that wants to book a court
:param a_booking_filter: the booking information
:param a_club: the club information
"""
async with ClientSession() as session:
gs_connector = GestionSportsConnector(session, tpc_url)
await gs_connector.connect()
await gs_connector.land()
await gs_connector.login(a_user, a_club)
court_booked = await gs_connector.book(a_booking_filter, a_club)
@ -67,11 +88,21 @@ async def test_booking_url_should_be_reachable(a_user, a_booking_filter, a_club)
@pytest.mark.asyncio
async def test_should_book_a_court_from_gestion_sports(
aioresponses,
a_booking_filter,
a_club,
a_booking_success_response,
a_booking_failure_response,
):
a_booking_filter: BookingFilter,
a_club: Club,
a_booking_success_response: str,
a_booking_failure_response: str,
) -> None:
"""
Test that user can reach the landing page, then log in to the platform
and eventually book a court
:param aioresponses: the http response mock
:param a_booking_filter: the booking information
:param a_club: the club information
:param a_booking_success_response: the success response mock
:param a_booking_failure_response: the failure response mock
"""
booking_url = URL(tpc_url + "/membre/reservation.html?")
# first booking request will fail
@ -89,20 +120,40 @@ async def test_should_book_a_court_from_gestion_sports(
assert court_booked == a_club.courts_ids[1]
def test_response_status_should_be_ok(a_booking_success_response):
def test_response_status_should_be_ok(a_booking_success_response: str) -> None:
"""
Test internal method to verify that the success response received by booking
a gestion-sports court is still a JSON with a field 'status' set to 'ok'
:param a_booking_success_response: the success response mock
"""
is_booked = GestionSportsConnector.is_response_status_ok(a_booking_success_response)
assert is_booked
def test_response_status_should_be_not_ok(a_booking_failure_response):
def test_response_status_should_be_not_ok(a_booking_failure_response: str) -> None:
"""
Test internal method to verify that the failure response received by booking
a gestion-sports court is still a JSON with a field 'status' set to 'error'
:param a_booking_failure_response: the failure response mock
"""
is_booked = GestionSportsConnector.is_response_status_ok(a_booking_failure_response)
assert not is_booked
@pytest.mark.asyncio
async def test_court_should_not_be_booked(
aioresponses, a_booking_payload, a_booking_failure_response
):
aioresponses, a_booking_payload: str, a_booking_failure_response: str
) -> None:
"""
Test that no court is booked when there is a failure response
from the booking request
:param aioresponses: the http requests mock
:param a_booking_payload: the payload that is sent for booking
:param a_booking_failure_response: the failure response mock
"""
async with ClientSession() as session:
tpc_connector = GestionSportsConnector(session, tpc_url)
aioresponses.post(
@ -114,8 +165,16 @@ async def test_court_should_not_be_booked(
@pytest.mark.asyncio
async def test_court_should_be_booked(
aioresponses, a_booking_payload, a_booking_success_response
):
aioresponses, a_booking_payload: str, a_booking_success_response: str
) -> None:
"""
Test that a court is booked when there is a success response
from the booking request
:param aioresponses: the http requests mock
:param a_booking_payload: the payload that is sent for booking
:param a_booking_success_response: the success response mock
"""
async with ClientSession() as session:
tpc_connector = GestionSportsConnector(session, tpc_url)