added available users in config

This commit is contained in:
Stanislas Jouffroy 2024-02-20 18:47:11 +01:00
parent 52b962c709
commit d0a0072b6d
2 changed files with 93 additions and 0 deletions

View file

@ -64,6 +64,25 @@ def get_user() -> User:
return User(login=login, password=password)
def get_available_users() -> list[User]:
"""
Read the environment variables to get all the available users in order
to increase the chance of having a user with a free slot for a booking
:return: the list of all users that can book a court
"""
available_users_credentials = os.environ.get("AVAILABLE_USERS_CREDENTIALS")
available_users = [
credential for credential in available_users_credentials.split(",")
]
users = []
for user in available_users:
login, password = user.split(":")
users.append(User(login=login, password=password))
return users
def get_post_headers(platform_id: str) -> dict:
"""
Get the headers for the POST endpoint related to a specific booking platform

74
tests/test_config.py Normal file
View file

@ -0,0 +1,74 @@
import os
from unittest.mock import patch
import config
from pendulum import DateTime, Time, Timezone
@patch.dict(
os.environ,
{
"CLUB_URL": "club.url",
"COURT_IDS": "7,8,10",
"CLUB_ID": "666",
"BOOKING_OPEN_DAYS_BEFORE": "5",
"BOOKING_OPENING_TIME": "18:37",
},
clear=True,
)
def test_get_club():
club = config.get_club()
assert club.url == "club.url"
assert club.courts_ids == [7, 8, 10]
assert club.id == "666"
assert club.booking_open_days_before == 5
assert club.booking_opening_time == Time(hour=18, minute=37)
@patch.dict(
os.environ,
{
"SPORT_ID": "666",
"DATE_TIME": "2024-02-03T22:38:45Z",
},
clear=True,
)
def test_get_booking_filter():
booking_filter = config.get_booking_filter()
assert booking_filter.sport_id == 666
assert booking_filter.date == DateTime(
year=2024,
month=2,
day=3,
hour=23,
minute=38,
second=45,
tzinfo=Timezone("Europe/Paris"),
)
@patch.dict(
os.environ,
{
"LOGIN": "login@user.tld",
"PASSWORD": "gloups",
},
clear=True,
)
def test_get_available_user():
user = config.get_user()
assert user.login == "login@user.tld"
assert user.password == "gloups"
@patch.dict(
os.environ,
{"AVAILABLE_USERS_CREDENTIALS": "login@user.tld:gloups,other@user.tld:patatras"},
clear=True,
)
def test_user():
users = config.get_available_users()
assert users[0].login == "login@user.tld"
assert users[0].password == "gloups"
assert users[1].login == "other@user.tld"
assert users[1].password == "patatras"