refactor: split backend domains and add API behavior coverage

This commit is contained in:
3252a8
2026-05-13 18:38:10 +03:00
parent a96007d48a
commit 7401649841
103 changed files with 10558 additions and 9832 deletions
+2 -2
View File
@@ -76,7 +76,7 @@ class ActionLoggerMiddleware(BaseMiddleware):
user_exists = await user_dal.get_user_by_id(session, user_id)
if not user_exists:
logging.warning(
f"ActionLoggerMiddleware: User {user_id} not found in DB. Logging action with user_id=NULL."
f"ActionLoggerMiddleware: User {user_id} not found in DB. Logging action with user_id=NULL." # noqa: E501
)
log_user_id_for_db = None
@@ -95,7 +95,7 @@ class ActionLoggerMiddleware(BaseMiddleware):
await message_log_dal.create_message_log_no_commit(session, log_payload)
except Exception as e_log:
logging.error(
f"ActionLoggerMiddleware: Failed to add log to session for user {user_id}, type {current_event_type}: {e_log}",
f"ActionLoggerMiddleware: Failed to add log to session for user {user_id}, type {current_event_type}: {e_log}", # noqa: E501
exc_info=True,
)
+2 -2
View File
@@ -49,7 +49,7 @@ class BanCheckMiddleware(BaseMiddleware):
if db_user_model and db_user_model.is_banned:
logging.info(
f"User {event_user.id} ({event_user.username or 'NoUsername'}) is banned. Blocking access."
f"User {event_user.id} ({event_user.username or 'NoUsername'}) is banned. Blocking access." # noqa: E501
)
i18n_data_from_event = data.get("i18n_data", {})
@@ -113,7 +113,7 @@ class BanCheckMiddleware(BaseMiddleware):
logging.warning(f"BanCheck: Bot is blocked by user {event_user.id}.")
except Exception as e_send:
logging.error(
f"BanCheck: Failed to notify banned user {event_user.id}: {type(e_send).__name__} - {e_send}",
f"BanCheck: Failed to notify banned user {event_user.id}: {type(e_send).__name__} - {e_send}", # noqa: E501
exc_info=True,
)
+2 -2
View File
@@ -19,7 +19,7 @@ class ChannelSubscriptionMiddleware(BaseMiddleware):
"""
Blocks access to handlers for users who have not yet passed the required channel subscription check.
The /start command is allowed through so that the handler can re-run the verification.
"""
""" # noqa: E501
def __init__(self, settings: Settings, i18n_instance: JsonI18n):
super().__init__()
@@ -126,7 +126,7 @@ class ChannelSubscriptionMiddleware(BaseMiddleware):
await callback.message.answer(prompt_text, reply_markup=keyboard)
except Exception as send_error:
logging.error(
"ChannelSubscriptionMiddleware: failed to send prompt for callback in chat %s: %s",
"ChannelSubscriptionMiddleware: failed to send prompt for callback in chat %s: %s", # noqa: E501
callback.message.chat.id,
send_error,
exc_info=True,
+7 -7
View File
@@ -19,7 +19,7 @@ class JsonI18n:
self.locales_data: Dict[str, Dict[str, str]] = {}
self._load_locales()
logging.info(
f"JsonI18n initialized. Loaded languages: {list(self.locales_data.keys())}. Default: {self.default_lang}"
f"JsonI18n initialized. Loaded languages: {list(self.locales_data.keys())}. Default: {self.default_lang}" # noqa: E501
)
def _load_locales(self):
@@ -35,7 +35,7 @@ class JsonI18n:
self.locales_data[lang_code] = json.load(f)
except json.JSONDecodeError as e_json_load:
logging.error(
f"Error loading locale {lang_code} from {file_path} (JSON Decode Error): {e_json_load}"
f"Error loading locale {lang_code} from {file_path} (JSON Decode Error): {e_json_load}" # noqa: E501
)
except Exception as e_load:
logging.error(
@@ -66,7 +66,7 @@ class JsonI18n:
except Exception:
return text
logging.warning(
f"No language data for '{effective_lang_code}' (default '{self.default_lang}' also missing). Key '{key}' will be returned as is."
f"No language data for '{effective_lang_code}' (default '{self.default_lang}' also missing). Key '{key}' will be returned as is." # noqa: E501
)
return key.format(**kwargs) if kwargs else key
@@ -78,19 +78,19 @@ class JsonI18n:
if text is None:
logging.warning(
f"Translation key '{key}' not found for lang '{effective_lang_code}' or default '{self.default_lang}'. Returning key."
f"Translation key '{key}' not found for lang '{effective_lang_code}' or default '{self.default_lang}'. Returning key." # noqa: E501
)
return key.format(**kwargs) if kwargs else key
try:
return text.format(**kwargs) if kwargs else text
except KeyError as e_format:
logging.warning(
f"Missing format key '{e_format}' for i18n key '{key}' (lang: {effective_lang_code}). Original text: '{text}'"
f"Missing format key '{e_format}' for i18n key '{key}' (lang: {effective_lang_code}). Original text: '{text}'" # noqa: E501
)
return text
except Exception as e_general_format:
logging.error(
f"General error formatting i18n key '{key}' (lang: {effective_lang_code}): {e_general_format}. Original text: '{text}'",
f"General error formatting i18n key '{key}' (lang: {effective_lang_code}): {e_general_format}. Original text: '{text}'", # noqa: E501
exc_info=True,
)
return text
@@ -147,7 +147,7 @@ class I18nMiddleware(BaseMiddleware):
current_language = event_user.language_code.lower()
except Exception as e_db_lang:
logging.error(
f"I18nMiddleware: Error fetching user lang from DB for {event_user.id}: {e_db_lang}. Falling back.",
f"I18nMiddleware: Error fetching user lang from DB for {event_user.id}: {e_db_lang}. Falling back.", # noqa: E501
exc_info=True,
)
if event_user.language_code:
+3 -3
View File
@@ -43,7 +43,7 @@ class ProfileSyncMiddleware(BaseMiddleware):
if update_payload:
await user_dal.update_user(session, db_user.user_id, update_payload)
logging.info(
f"ProfileSyncMiddleware: Updated user {tg_user.id} profile fields: {list(update_payload.keys())}"
f"ProfileSyncMiddleware: Updated user {tg_user.id} profile fields: {list(update_payload.keys())}" # noqa: E501
)
# Also update description on panel if linked
@@ -72,11 +72,11 @@ class ProfileSyncMiddleware(BaseMiddleware):
)
except Exception as e_upd_desc:
logging.warning(
f"ProfileSyncMiddleware: Failed to update panel description for user {tg_user.id}: {e_upd_desc}"
f"ProfileSyncMiddleware: Failed to update panel description for user {tg_user.id}: {e_upd_desc}" # noqa: E501
)
except Exception as e:
logging.error(
f"ProfileSyncMiddleware: Failed to sync profile for user {getattr(tg_user, 'id', 'N/A')}: {e}",
f"ProfileSyncMiddleware: Failed to sync profile for user {getattr(tg_user, 'id', 'N/A')}: {e}", # noqa: E501
exc_info=True,
)