All methods are in the right class

This commit is contained in:
Stanislas Jouffroy 2024-03-23 21:54:17 +01:00
parent 0d541e82a5
commit 7f59443b64
12 changed files with 585 additions and 1729 deletions

View file

@ -61,7 +61,7 @@ def set_tournaments_sessions_response(
aioresponses, connector: GestionSportsConnector, tournaments_sessions_response
):
aioresponses.post(
connector.tournaments_sessions_url,
connector.sessions_url,
status=200,
body=tournaments_sessions_response,
)
@ -73,7 +73,7 @@ def set_tournaments_list_response(
tournament_id,
tournaments_list_response,
):
url = f"{connector.tournaments_list_url}{tournament_id}"
url = f"{connector.tournaments_url}{tournament_id}"
aioresponses.get(url, status=200, body=tournaments_list_response)
@ -84,7 +84,7 @@ def set_full_user_bookings_responses(aioresponses, connector, responses):
def set_cancellation_response(aioresponses, connector, response):
aioresponses.post(connector.booking_cancellation_url, status=200, payload=response)
aioresponses.post(connector.cancel_url, status=200, payload=response)
def set_full_cancellation_by_id_responses(aioresponses, connector, responses):

View file

@ -16,9 +16,9 @@ def test_urls(connector, club):
assert connector.login_url == f"{base_url}/login.html"
assert connector.booking_url == f"{base_url}/booking.html"
assert connector.user_bookings_url == f"{base_url}/user_bookings.html"
assert connector.booking_cancellation_url == f"{base_url}/cancel.html"
assert connector.tournaments_sessions_url == f"{base_url}/tournaments_sessions.php"
assert connector.tournaments_list_url == f"{base_url}/tournaments_list.html?event="
assert connector.cancel_url == f"{base_url}/cancel.html"
assert connector.sessions_url == f"{base_url}/tournaments_sessions.php"
assert connector.tournaments_url == f"{base_url}/tournaments_list.html?event="
@patch("config.get_resources_folder")
@ -41,11 +41,11 @@ def test_urls_payload_templates(mock_resources, club):
== path_to_resources / "gestion-sports/user-bookings-payload.txt"
)
assert (
connector.booking_cancel_template
connector.cancel_template
== path_to_resources / "gestion-sports/booking-cancellation-payload.txt"
)
assert (
connector.tournaments_sessions_template
connector.sessions_template
== path_to_resources / "gestion-sports/tournament-sessions-payload.txt"
)
@ -90,29 +90,6 @@ async def test_login_failure(aioresponses, connector, user, login_failure_respon
assert await response.json() == login_failure_response
def test_get_booked_court(connector, booked_courts_response):
booked_court = connector.get_booked_court(booked_courts_response, "Sport1")
assert booked_court.number == 3
@pytest.mark.asyncio
async def test_get_ongoing_bookings(
aioresponses,
connector,
user,
user_bookings_get_response,
user_bookings_list,
):
responses.set_ongoing_bookings_response(
aioresponses, connector, user_bookings_get_response, user_bookings_list
)
async with ClientSession() as session:
bookings = await connector.get_ongoing_bookings(session)
assert len(bookings) == 2
@pytest.mark.asyncio
async def test_cancellation_request(
aioresponses, connector, user_bookings_get_response, cancellation_response
@ -121,31 +98,11 @@ async def test_cancellation_request(
responses.set_cancellation_response(aioresponses, connector, cancellation_response)
async with ClientSession() as session:
response = await connector.cancel_booking_id(session, 123)
response = await connector.send_cancellation_request(session, 123, "hash")
assert await response.json() == cancellation_response
@pytest.mark.asyncio
async def test_cancel_booking_success(
aioresponses,
connector,
user,
cancellation_success_booking_filter,
cancellation_success_from_start,
):
responses.set_full_cancellation_responses(
aioresponses, connector, cancellation_success_from_start
)
async with ClientSession() as session:
response = await connector.cancel_booking(
session, cancellation_success_booking_filter
)
assert await response.json() == cancellation_success_from_start[4]
@pytest.mark.asyncio
async def test_tournament_sessions(
aioresponses, connector, user, tournament_sessions_json
@ -154,7 +111,7 @@ async def test_tournament_sessions(
aioresponses, connector, tournament_sessions_json
)
async with ClientSession() as session:
response = await connector.send_tournaments_sessions_request(session)
response = await connector.send_session_request(session)
assert response.status == 200

View file

@ -11,6 +11,7 @@ from tests.unit_tests import responses
@pytest.mark.asyncio
async def test_booking_success(
aioresponses,
gs_services,
connector,
club,
user,
@ -21,7 +22,7 @@ async def test_booking_success(
aioresponses, connector, booking_success_from_start
)
court_booked = await GestionSportsServices.book(club, user, booking_filter)
court_booked = await gs_services.book(club, user, booking_filter)
assert court_booked.id == 2
@ -45,6 +46,11 @@ async def test_booking_failure(
assert court_booked is None
def test_get_booked_court(gs_services, booked_courts_response, sport1):
booked_court = gs_services.get_booked_court(booked_courts_response, sport1)
assert booked_court.number == 3
@pytest.mark.asyncio
async def test_user_has_available_booking_slots(
aioresponses,
@ -98,22 +104,6 @@ async def test_cancel_booking(
await gs_services.cancel_booking(user, club, booking_filter)
@pytest.mark.asyncio
async def test_cancel_booking_id(
aioresponses,
gs_services,
connector,
user,
club,
cancellation_success_from_start,
):
responses.set_full_cancellation_responses(
aioresponses, connector, cancellation_success_from_start
)
await gs_services.cancel_booking_id(user, club, 65464)
@patch("pendulum.now")
def test_wait_until_booking_time(mock_now, club, user):
booking_filter = BookingFilter(