Ability to book a single court at a given time with gestion-sports
This commit is contained in:
parent
3f18f0f4a2
commit
e953a4110b
14 changed files with 489 additions and 66 deletions
0
tests/gestion_sports/__init__.py
Normal file
0
tests/gestion_sports/__init__.py
Normal file
|
@ -1,14 +1,26 @@
|
|||
import json
|
||||
|
||||
import pendulum
|
||||
import pytest
|
||||
from aiohttp import ClientSession
|
||||
from yarl import URL
|
||||
|
||||
from resa_padel.gestion_sports_connector import GestionSportsConnector
|
||||
from resa_padel.gestion_sports.gestion_sports_connector import GestionSportsConnector
|
||||
from resa_padel.models import User, BookingFilter
|
||||
|
||||
gestion_sports_url = "https://toulousepadelclub.gestion-sports.com"
|
||||
test_user = "padel.testing@jouf.fr"
|
||||
test_user_id = "232382"
|
||||
test_password = "ridicule"
|
||||
test_club_id = "88"
|
||||
user = User(login=test_user, password=test_password, club_id=test_club_id)
|
||||
test_court_id = "607"
|
||||
|
||||
now = pendulum.now()
|
||||
date_to_book = now.add(days=6)
|
||||
datetime_to_book = date_to_book.set(hour=18, minute=0, second=0)
|
||||
padel_id = 217
|
||||
court_id = 607
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -36,7 +48,7 @@ async def test_should_login_to_gestion_sports_website():
|
|||
gs_connector = GestionSportsConnector(session, gestion_sports_url)
|
||||
await gs_connector.connect()
|
||||
|
||||
response = await gs_connector.login(test_user, test_password, test_club_id)
|
||||
response = await gs_connector.login(user)
|
||||
|
||||
assert response.status == 200
|
||||
assert response.request_info.url == URL(gestion_sports_url + "/connexion.php")
|
||||
|
@ -46,3 +58,28 @@ async def test_should_login_to_gestion_sports_website():
|
|||
assert cookies.get("COOK_ID_CLUB").value == test_club_id
|
||||
assert cookies.get("COOK_ID_USER").value == test_user_id
|
||||
assert cookies.get("PHPSESSID") is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_should_book_a_court_from_gestion_sports():
|
||||
async with ClientSession() as session:
|
||||
gs_connector = GestionSportsConnector(session, gestion_sports_url)
|
||||
await gs_connector.connect()
|
||||
await gs_connector.login(user)
|
||||
|
||||
booking_filter = BookingFilter(
|
||||
court_id=court_id, sport_id=padel_id, date=datetime_to_book
|
||||
)
|
||||
response = await gs_connector.book(booking_filter)
|
||||
|
||||
assert response.status == 200
|
||||
assert response.request_info.url == URL(
|
||||
gestion_sports_url + "/membre/reservation.html?"
|
||||
)
|
||||
assert response.request_info.method == "POST"
|
||||
|
||||
result = await response.text()
|
||||
formatted_result = result.removeprefix('"').removesuffix('"')
|
||||
result_json = json.loads(formatted_result)
|
||||
# booking any day at 18:00 should always be an error if everything goes well ;)
|
||||
assert result_json["status"] == "error"
|
44
tests/gestion_sports/test_gestion_sports_payload_builder.py
Normal file
44
tests/gestion_sports/test_gestion_sports_payload_builder.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import pendulum
|
||||
|
||||
from resa_padel.gestion_sports.gestion_sports_payload_builder import (
|
||||
GestionSportsPayloadBuilder,
|
||||
)
|
||||
|
||||
|
||||
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()
|
||||
)
|
||||
|
||||
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")
|
||||
|
||||
|
||||
def test_booking_payload_should_be_built():
|
||||
booking_builder = GestionSportsPayloadBuilder()
|
||||
booking_date = pendulum.now("Europe/Paris")
|
||||
sport_id = "27"
|
||||
court_id = "55"
|
||||
booking_payload = (
|
||||
booking_builder.date(booking_date.date())
|
||||
.time(booking_date.time())
|
||||
.sport_id(sport_id)
|
||||
.court_id(court_id)
|
||||
.build_booking_payload()
|
||||
)
|
||||
|
||||
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")
|
|
@ -7,6 +7,7 @@ from resa_padel import booking
|
|||
user = "user"
|
||||
password = "password"
|
||||
club_id = "98"
|
||||
court_id = "11"
|
||||
|
||||
|
||||
# FIXME
|
||||
|
@ -34,9 +35,10 @@ def test_booking_does_the_rights_calls():
|
|||
)
|
||||
|
||||
session = loop.run_until_complete(
|
||||
booking.book(booking_url, user, password, club_id)
|
||||
booking.book(booking_url, user, password, club_id, court_id)
|
||||
)
|
||||
|
||||
cookies = session.cookie_jar.filter_cookies(booking_url)
|
||||
# assert cookies.get("connection_called") == "True"
|
||||
# assert cookies.get("login_called") == "True"
|
||||
# assert cookies.get("booking_called") == "True"
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
from resa_padel.gestion_sports_payload_builder import GestionSportsPayloadBuilder
|
||||
|
||||
|
||||
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()
|
||||
)
|
||||
|
||||
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")
|
Loading…
Add table
Add a link
Reference in a new issue