101 lines
3.1 KiB
Python
101 lines
3.1 KiB
Python
from app.config import Settings
|
|
|
|
|
|
def test_database_server_url_excludes_database_name() -> None:
|
|
settings = Settings.model_construct(
|
|
db_host="127.0.0.1",
|
|
db_port=3306,
|
|
db_name="oreolvpn",
|
|
db_user="user",
|
|
db_password="pass",
|
|
)
|
|
|
|
assert settings.database_server_url == "mysql+aiomysql://user:pass@127.0.0.1:3306/?charset=utf8mb4"
|
|
|
|
|
|
def test_support_ticket_link_parses_private_topic_link() -> None:
|
|
settings = Settings.model_construct(
|
|
bot_support_ticket_link="https://t.me/c/3646494169/2/3",
|
|
bot_support_ticket_chat_id_raw="",
|
|
bot_support_ticket_thread_id=0,
|
|
)
|
|
|
|
assert settings.support_ticket_chat_id == -1003646494169
|
|
assert settings.support_ticket_message_thread_id == 2
|
|
|
|
|
|
def test_payment_review_link_parses_private_topic_link() -> None:
|
|
settings = Settings.model_construct(
|
|
payment_review_link="https://t.me/c/3646494169/56/57",
|
|
payment_review_chat_id_raw="",
|
|
payment_review_thread_id=0,
|
|
)
|
|
|
|
assert settings.payment_review_chat_id == -1003646494169
|
|
assert settings.payment_review_message_thread_id == 56
|
|
|
|
|
|
def test_moderator_ids_are_parsed() -> None:
|
|
settings = Settings.model_construct(
|
|
bot_moderator_ids_raw="123, 456 ,789",
|
|
)
|
|
|
|
assert settings.bot_moderator_ids == {123, 456, 789}
|
|
assert settings.is_moderator(456) is True
|
|
assert settings.is_moderator(999) is False
|
|
|
|
|
|
def test_public_username_is_normalized() -> None:
|
|
settings = Settings.model_construct(
|
|
bot_public_username="@oreol_vpn_bot",
|
|
)
|
|
|
|
assert settings.bot_public_username_normalized == "oreol_vpn_bot"
|
|
|
|
|
|
def test_payment_internal_squad_uuids_are_parsed() -> None:
|
|
settings = Settings.model_construct(
|
|
payment_internal_squad_uuids_raw="uuid-1, uuid-2 ,uuid-3",
|
|
)
|
|
|
|
assert settings.payment_internal_squad_uuids == ["uuid-1", "uuid-2", "uuid-3"]
|
|
|
|
|
|
def test_payment_username_prefix_is_normalized() -> None:
|
|
settings = Settings.model_construct(
|
|
payment_username_prefix="Oreol!! prefix",
|
|
)
|
|
|
|
assert settings.payment_username_prefix_normalized == "Oreolprefix"
|
|
|
|
|
|
def test_payment_plans_are_parsed() -> None:
|
|
settings = Settings.model_construct(
|
|
payment_plans_raw="30:250,180:600,365:1000",
|
|
)
|
|
|
|
plans = settings.payment_plans
|
|
|
|
assert [plan.code for plan in plans] == ["30d", "180d", "365d"]
|
|
assert [plan.days for plan in plans] == [30, 180, 365]
|
|
assert [plan.amount_rub for plan in plans] == [250, 600, 1000]
|
|
|
|
|
|
def test_payment_product_plans_override_legacy_plans() -> None:
|
|
settings = Settings.model_construct(
|
|
payment_product_plans_raw="vpn_white:30:450,white:30:250,vpn:30:200",
|
|
payment_plans_raw="30:999",
|
|
payment_plan_duration_days=30,
|
|
)
|
|
|
|
plans = settings.payment_plans
|
|
|
|
assert [plan.code for plan in plans] == ["vpn_white", "white", "vpn"]
|
|
assert [plan.title for plan in plans] == ["VPN + Белые списки", "Белые списки", "VPN"]
|
|
assert [plan.amount_rub for plan in plans] == [450, 250, 200]
|
|
assert [plan.squad_groups for plan in plans] == [
|
|
("vpn", "white"),
|
|
("white",),
|
|
("vpn",),
|
|
]
|