chore: run lint and prettifier

This commit is contained in:
3252a8
2026-05-12 21:54:12 +03:00
parent f31540afdb
commit 11187487b4
174 changed files with 12383 additions and 6688 deletions
+51 -12
View File
@@ -86,10 +86,24 @@ class AdminGrantTopupTests(unittest.IsolatedAsyncioTestCase):
updated_sub.traffic_limit_bytes = 155 * (1024**3)
updated_sub.is_throttled = False
with patch("bot.services.subscription_service.user_dal.get_user_by_id", new=AsyncMock(return_value=db_user)), \
patch("bot.services.subscription_service.subscription_dal.get_active_subscription_by_user_id", new=AsyncMock(return_value=sub)), \
patch("bot.services.subscription_service.subscription_dal.update_subscription", new=AsyncMock(return_value=updated_sub)) as upd, \
patch("bot.services.subscription_service.tariff_dal.create_traffic_topup", new=AsyncMock()) as topup_log:
with (
patch(
"bot.services.subscription_service.user_dal.get_user_by_id",
new=AsyncMock(return_value=db_user),
),
patch(
"bot.services.subscription_service.subscription_dal.get_active_subscription_by_user_id",
new=AsyncMock(return_value=sub),
),
patch(
"bot.services.subscription_service.subscription_dal.update_subscription",
new=AsyncMock(return_value=updated_sub),
) as upd,
patch(
"bot.services.subscription_service.tariff_dal.create_traffic_topup",
new=AsyncMock(),
) as topup_log,
):
result = await service.admin_grant_topup(AsyncMock(), 42, 50.0)
self.assertIsNotNone(result)
@@ -156,10 +170,24 @@ class AdminGrantTopupTests(unittest.IsolatedAsyncioTestCase):
)
updated_sub = SimpleNamespace(**vars(sub))
with patch("bot.services.subscription_service.user_dal.get_user_by_id", new=AsyncMock(return_value=db_user)), \
patch("bot.services.subscription_service.subscription_dal.get_active_subscription_by_user_id", new=AsyncMock(return_value=sub)), \
patch("bot.services.subscription_service.subscription_dal.update_subscription", new=AsyncMock(return_value=updated_sub)) as upd, \
patch("bot.services.subscription_service.tariff_dal.create_traffic_topup", new=AsyncMock()) as topup_log:
with (
patch(
"bot.services.subscription_service.user_dal.get_user_by_id",
new=AsyncMock(return_value=db_user),
),
patch(
"bot.services.subscription_service.subscription_dal.get_active_subscription_by_user_id",
new=AsyncMock(return_value=sub),
),
patch(
"bot.services.subscription_service.subscription_dal.update_subscription",
new=AsyncMock(return_value=updated_sub),
) as upd,
patch(
"bot.services.subscription_service.tariff_dal.create_traffic_topup",
new=AsyncMock(),
) as topup_log,
):
result = await service.admin_grant_premium_topup(AsyncMock(), 77, 20.0)
self.assertIsNotNone(result)
@@ -187,12 +215,23 @@ class AdminGrantTopupTests(unittest.IsolatedAsyncioTestCase):
service = SubscriptionService(settings, AsyncMock(spec=PanelApiService))
db_user = SimpleNamespace(
user_id=11, panel_user_uuid="panel-uuid",
user_id=11,
panel_user_uuid="panel-uuid",
)
sub = SimpleNamespace(
subscription_id=1, user_id=11, panel_user_uuid="panel-uuid", tariff_key="standard"
)
sub = SimpleNamespace(subscription_id=1, user_id=11, panel_user_uuid="panel-uuid", tariff_key="standard")
with patch("bot.services.subscription_service.user_dal.get_user_by_id", new=AsyncMock(return_value=db_user)), \
patch("bot.services.subscription_service.subscription_dal.get_active_subscription_by_user_id", new=AsyncMock(return_value=sub)):
with (
patch(
"bot.services.subscription_service.user_dal.get_user_by_id",
new=AsyncMock(return_value=db_user),
),
patch(
"bot.services.subscription_service.subscription_dal.get_active_subscription_by_user_id",
new=AsyncMock(return_value=sub),
),
):
self.assertIsNone(await service.admin_grant_premium_topup(AsyncMock(), 11, 10.0))
+7 -1
View File
@@ -18,7 +18,13 @@ class MiniAppUrlTests(unittest.TestCase):
)
def test_subscription_mini_app_topup_url_none_when_unset(self):
s = Settings(_env_file=None, BOT_TOKEN="x", POSTGRES_USER="u", POSTGRES_PASSWORD="p", SUBSCRIPTION_MINI_APP_URL=None)
s = Settings(
_env_file=None,
BOT_TOKEN="x",
POSTGRES_USER="u",
POSTGRES_PASSWORD="p",
SUBSCRIPTION_MINI_APP_URL=None,
)
self.assertIsNone(subscription_mini_app_topup_url(s, "regular"))
def test_subscription_mini_app_topup_url(self):
+4 -2
View File
@@ -13,8 +13,8 @@ from bot.app.web.webapp_auth import (
create_webapp_session_token,
verify_telegram_oauth_nonce,
)
from bot.services.crypto_pay_service import CryptoPayService
from bot.handlers.user.payment import yookassa_webhook_route
from bot.services.crypto_pay_service import CryptoPayService
from bot.services.freekassa_service import FreeKassaService
from bot.utils.request_security import request_client_ip
@@ -280,7 +280,9 @@ class WebAppSecurityTests(unittest.IsolatedAsyncioTestCase):
self.assertIsNotNone(payload)
self.assertEqual(payload["referral_code"], "x" * 128)
self.assertEqual(len(payload["code_verifier"]), 43)
self.assertIsNone(subscription_webapp._read_telegram_oauth_state_payload(callback_request, state + "x"))
self.assertIsNone(
subscription_webapp._read_telegram_oauth_state_payload(callback_request, state + "x")
)
def test_telegram_oauth_client_id_defaults_to_bot_id(self):
settings = SimpleNamespace(
+1 -1
View File
@@ -1,5 +1,5 @@
import unittest
import json
import unittest
from pydantic import ValidationError
+14 -4
View File
@@ -69,7 +69,9 @@ class TariffWorkerTests(unittest.IsolatedAsyncioTestCase):
)
tariff = settings.tariffs_config.require("standard")
await worker._ensure_period_reset_strategy(sub, tariff, sub.traffic_limit_bytes, "NO_RESET")
await worker._ensure_period_reset_strategy(
sub, tariff, sub.traffic_limit_bytes, "NO_RESET"
)
panel_service.update_user_details_on_panel.assert_awaited_once()
panel_service.reset_user_traffic.assert_not_awaited()
@@ -112,7 +114,10 @@ class TariffWorkerTests(unittest.IsolatedAsyncioTestCase):
)
tariff = settings.tariffs_config.require("standard")
with patch("bot.services.tariff_worker.tariff_dal.get_warning", new=AsyncMock(return_value=True)):
with patch(
"bot.services.tariff_worker.tariff_dal.get_warning",
new=AsyncMock(return_value=True),
):
await worker._maybe_warn_or_throttle(
AsyncMock(),
sub,
@@ -175,7 +180,10 @@ class TariffWorkerTests(unittest.IsolatedAsyncioTestCase):
)
tariff = settings.tariffs_config.require("standard")
with patch("bot.services.tariff_worker.tariff_dal.get_warning", new=AsyncMock(return_value=True)):
with patch(
"bot.services.tariff_worker.tariff_dal.get_warning",
new=AsyncMock(return_value=True),
):
await worker._sync_premium_squad_limit(
AsyncMock(),
sub,
@@ -206,7 +214,9 @@ class TariffWorkerTests(unittest.IsolatedAsyncioTestCase):
TARIFF_TRAFFIC_WARNING_LEVELS="101",
)
panel_service = AsyncMock(spec=PanelApiService)
panel_service.get_internal_squad_accessible_nodes = AsyncMock(return_value=[{"uuid": "node-1"}])
panel_service.get_internal_squad_accessible_nodes = AsyncMock(
return_value=[{"uuid": "node-1"}]
)
panel_service.get_node_users_bandwidth_stats = AsyncMock(
return_value={
"topUsers": [
-1
View File
@@ -1,7 +1,6 @@
import json
import unittest
from config.tariffs_config import TariffsConfig, load_tariffs_config
+4 -4
View File
@@ -17,9 +17,7 @@ from bot.keyboards.inline.user_keyboards import (
class JsonI18nStub:
def __init__(self):
self.translations = json.loads(
Path("locales/en.json").read_text(encoding="utf-8")
)
self.translations = json.loads(Path("locales/en.json").read_text(encoding="utf-8"))
def gettext(self, lang, key, **kwargs):
text = self.translations[key]
@@ -108,7 +106,9 @@ class UserBotMenuTests(unittest.TestCase):
"https://app.example.com/invite?utm=channel&ref=uAbC123xYz",
)
self.assertEqual(subscription_webapp._normalize_referral_param("uAbC123xYz"), "ABC123XYZ")
self.assertEqual(subscription_webapp._normalize_referral_param("ref_uAbC123xYz"), "ABC123XYZ")
self.assertEqual(
subscription_webapp._normalize_referral_param("ref_uAbC123xYz"), "ABC123XYZ"
)
def test_referral_text_places_web_link_after_telegram_link(self):
text = self.i18n.gettext(
+6 -2
View File
@@ -176,7 +176,9 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase):
def test_resolve_webapp_js_asset_name_prefers_latest_minified_build(self):
with tempfile.TemporaryDirectory() as tmpdir:
asset_dir = Path(tmpdir)
(asset_dir / "subscription_webapp.js").write_text("console.log('fallback');", encoding="utf-8")
(asset_dir / "subscription_webapp.js").write_text(
"console.log('fallback');", encoding="utf-8"
)
old_asset = asset_dir / "subscription_webapp.min.11111111.js"
new_asset = asset_dir / "subscription_webapp.min.22222222.js"
old_asset.write_text("console.log('old');", encoding="utf-8")
@@ -204,5 +206,7 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase):
with patch.object(subscription_webapp, "ASSET_DIR", asset_dir):
response = await subscription_webapp.js_asset_route(request)
self.assertEqual(response.headers["Cache-Control"], "public, max-age=31536000, immutable")
self.assertEqual(
response.headers["Cache-Control"], "public, max-age=31536000, immutable"
)
self.assertEqual(response.text, "console.log('minified');")