Payloads are now built with Jinja templates
This commit is contained in:
parent
ccd019eb4c
commit
badced0a30
12 changed files with 222 additions and 175 deletions
|
@ -3,9 +3,7 @@ import json
|
|||
import pendulum
|
||||
import pytest
|
||||
|
||||
from resa_padel.gestion_sports.gestion_sports_payload_builder import (
|
||||
GestionSportsPayloadBuilder,
|
||||
)
|
||||
from gestion_sports.payload_builders import GestionSportsBookingPayloadBuilder
|
||||
from resa_padel.models import BookingFilter, Club, User
|
||||
|
||||
user = User(login="padel.testing@jouf.fr", password="ridicule", club_id="123")
|
||||
|
@ -38,12 +36,10 @@ booking_success_response = json.dumps(
|
|||
date_format = "%d/%m/%Y"
|
||||
time_format = "%H:%M"
|
||||
booking_payload = (
|
||||
GestionSportsPayloadBuilder()
|
||||
.date(booking_date.date().strftime(date_format))
|
||||
.time(booking_date.time().strftime(time_format))
|
||||
.sport_id(sport_id)
|
||||
GestionSportsBookingPayloadBuilder()
|
||||
.booking_filter(booking_filter)
|
||||
.court_id(courts[0])
|
||||
.build_booking_payload()
|
||||
.build()
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ from resa_padel.gestion_sports.gestion_sports_connector import GestionSportsConn
|
|||
from tests.fixtures import (
|
||||
a_booking_failure_response,
|
||||
a_booking_filter,
|
||||
a_booking_payload,
|
||||
a_booking_success_response,
|
||||
a_club,
|
||||
a_user,
|
||||
|
@ -140,46 +139,3 @@ def test_response_status_should_be_not_ok(a_booking_failure_response: str) -> No
|
|||
"""
|
||||
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: 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(
|
||||
URL(tpc_connector.booking_url), status=200, body=a_booking_failure_response
|
||||
)
|
||||
is_booked = await tpc_connector.is_court_booked(a_booking_payload)
|
||||
assert not is_booked
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_court_should_be_booked(
|
||||
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)
|
||||
|
||||
aioresponses.post(
|
||||
URL(tpc_connector.booking_url), status=200, body=a_booking_success_response
|
||||
)
|
||||
is_booked = await tpc_connector.is_court_booked(a_booking_payload)
|
||||
assert is_booked
|
||||
|
|
|
@ -1,44 +1,50 @@
|
|||
import pendulum
|
||||
|
||||
from resa_padel.gestion_sports.gestion_sports_payload_builder import (
|
||||
GestionSportsPayloadBuilder,
|
||||
from resa_padel.gestion_sports.payload_builders import (
|
||||
GestionSportsLoginPayloadBuilder,
|
||||
GestionSportsBookingPayloadBuilder,
|
||||
)
|
||||
from tests.fixtures import a_user, a_club, a_booking_filter
|
||||
|
||||
|
||||
def test_login_payload_should_be_built():
|
||||
payload_builder = GestionSportsPayloadBuilder()
|
||||
login = "jacques"
|
||||
password = "chirac"
|
||||
club_id = "27"
|
||||
login_payload = (
|
||||
payload_builder.login(login)
|
||||
.password(password)
|
||||
.club_id(club_id)
|
||||
.build_login_payload()
|
||||
def test_login_payload_should_be_built(a_user, a_club):
|
||||
"""
|
||||
Test that the login payload is filled with the right template
|
||||
and filled accordingly
|
||||
|
||||
:param a_user: the user information fixture
|
||||
:param a_club: the club information fixture
|
||||
"""
|
||||
payload_builder = GestionSportsLoginPayloadBuilder()
|
||||
login_payload = payload_builder.user(a_user).club(a_club).build()
|
||||
|
||||
expected_payload = (
|
||||
f"ajax=connexionUser&id_club={a_club.id}&email={a_user.login}&form_ajax=1"
|
||||
f"&pass={a_user.password}&compte=user&playeridonesignal=0"
|
||||
f"&identifiant=identifiant&externCo=true"
|
||||
)
|
||||
|
||||
assert login_payload == (
|
||||
f"ajax=connexionUser&id_club={club_id}&email={login}&form_ajax=1&pass={password}&compte"
|
||||
f"=user&playeridonesignal=0&identifiant=identifiant&externCo=true"
|
||||
).encode("utf-8")
|
||||
assert login_payload == expected_payload
|
||||
|
||||
|
||||
def test_booking_payload_should_be_built():
|
||||
booking_builder = GestionSportsPayloadBuilder()
|
||||
booking_date = pendulum.now("Europe/Paris")
|
||||
sport_id = "27"
|
||||
court_id = "55"
|
||||
def test_booking_payload_should_be_built(a_booking_filter):
|
||||
"""
|
||||
Test that the booking payload is filled with the right template
|
||||
and filled accordingly
|
||||
|
||||
:param a_booking_filter: the booking information fixture
|
||||
"""
|
||||
booking_builder = GestionSportsBookingPayloadBuilder()
|
||||
booking_payload = (
|
||||
booking_builder.date(booking_date.date())
|
||||
.time(booking_date.time())
|
||||
.sport_id(sport_id)
|
||||
.court_id(court_id)
|
||||
.build_booking_payload()
|
||||
booking_builder.booking_filter(a_booking_filter).court_id(4).build()
|
||||
)
|
||||
|
||||
assert booking_payload == (
|
||||
f"ajax=addResa&date={booking_date.date()}&hour={booking_date.time()}&duration=90"
|
||||
f"&partners=null|null|null&paiement=facultatif&idSport={sport_id}"
|
||||
f"&creaPartie=false&idCourt={court_id}&pay=false&token=undefined&totalPrice=44&saveCard=0"
|
||||
f"&foodNumber=0"
|
||||
).encode("utf-8")
|
||||
expected_date = a_booking_filter.date.date().strftime("%d/%m/%Y")
|
||||
expected_time = a_booking_filter.date.time().strftime("%H:%M")
|
||||
expected_payload = (
|
||||
f"ajax=addResa&date={expected_date}"
|
||||
f"&hour={expected_time}&duration=90&partners=null|null|null"
|
||||
f"&paiement=facultatif&idSport={a_booking_filter.sport_id}"
|
||||
f"&creaPartie=false&idCourt=4&pay=false&token=undefined&totalPrice=44"
|
||||
f"&saveCard=0&foodNumber=0"
|
||||
)
|
||||
|
||||
assert booking_payload == expected_payload
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue