правки
This commit is contained in:
@@ -1024,7 +1024,6 @@ async def check_missing_bonuses(
|
||||
):
|
||||
"""Проверяет по БД — всем ли рефералам начислены бонусы."""
|
||||
from app.services.referral_diagnostics_service import (
|
||||
MissingBonusReport,
|
||||
referral_diagnostics_service,
|
||||
)
|
||||
|
||||
@@ -1057,13 +1056,13 @@ async def check_missing_bonuses(
|
||||
for i, mb in enumerate(report.missing_bonuses[:15], 1):
|
||||
referral_name = mb.referral_full_name or mb.referral_username or str(mb.referral_telegram_id)
|
||||
referrer_name = mb.referrer_full_name or mb.referrer_username or str(mb.referrer_telegram_id)
|
||||
text += f"\n{i}. <b>{referral_name}</b>"
|
||||
text += f"\n └ Пригласил: {referrer_name}"
|
||||
text += f"\n └ Пополнение: {mb.first_topup_amount_kopeks / 100:.0f}₽"
|
||||
text += f"\n └ Бонусы: {mb.referral_bonus_amount / 100:.0f}₽ + {mb.referrer_bonus_amount / 100:.0f}₽"
|
||||
text += f'\n{i}. <b>{referral_name}</b>'
|
||||
text += f'\n └ Пригласил: {referrer_name}'
|
||||
text += f'\n └ Пополнение: {mb.first_topup_amount_kopeks / 100:.0f}₽'
|
||||
text += f'\n └ Бонусы: {mb.referral_bonus_amount / 100:.0f}₽ + {mb.referrer_bonus_amount / 100:.0f}₽'
|
||||
|
||||
if len(report.missing_bonuses) > 15:
|
||||
text += f"\n\n<i>... и ещё {len(report.missing_bonuses) - 15} чел.</i>"
|
||||
text += f'\n\n<i>... и ещё {len(report.missing_bonuses) - 15} чел.</i>'
|
||||
|
||||
keyboard = types.InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
@@ -1095,7 +1094,6 @@ async def apply_missing_bonuses(
|
||||
):
|
||||
"""Применяет начисление пропущенных бонусов."""
|
||||
from app.services.referral_diagnostics_service import (
|
||||
MissingBonus,
|
||||
MissingBonusReport,
|
||||
referral_diagnostics_service,
|
||||
)
|
||||
@@ -1200,7 +1198,7 @@ async def sync_referrals_with_contest(
|
||||
total_skipped += stats.get('skipped', 0)
|
||||
contest_results.append(f"• {contest.title}: +{stats.get('created', 0)} новых")
|
||||
else:
|
||||
contest_results.append(f"• {contest.title}: ошибка")
|
||||
contest_results.append(f'• {contest.title}: ошибка')
|
||||
|
||||
text = f"""
|
||||
🏆 <b>Синхронизация с конкурсами завершена!</b>
|
||||
@@ -1420,7 +1418,7 @@ async def receive_log_file(message: types.Message, db_user: User, db: AsyncSessi
|
||||
await status_message.edit_text(
|
||||
f'❌ <b>Ошибка при анализе файла</b>\n\n'
|
||||
f'Файл: {file_name}\n'
|
||||
f'Ошибка: {str(e)}\n\n'
|
||||
f'Ошибка: {e!s}\n\n'
|
||||
f'Проверьте, что файл является текстовым логом бота.',
|
||||
reply_markup=types.InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
@@ -1431,7 +1429,7 @@ async def receive_log_file(message: types.Message, db_user: User, db: AsyncSessi
|
||||
)
|
||||
except:
|
||||
await message.answer(
|
||||
f'❌ Ошибка при анализе файла: {str(e)}',
|
||||
f'❌ Ошибка при анализе файла: {e!s}',
|
||||
reply_markup=types.InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[types.InlineKeyboardButton(text='⬅️ Назад', callback_data='admin_referral_diagnostics')]
|
||||
|
||||
@@ -459,7 +459,7 @@ class ReferralDiagnosticsService:
|
||||
date_prefix = start_date.strftime('%Y-%m-%d') if use_date_prefix else None
|
||||
|
||||
try:
|
||||
with open(self.log_path, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
with open(self.log_path, encoding='utf-8', errors='ignore') as f:
|
||||
for line in f:
|
||||
total_lines += 1
|
||||
line = line.strip()
|
||||
|
||||
@@ -7,9 +7,7 @@ from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.database.models import User
|
||||
from app.services.referral_diagnostics_service import ReferralDiagnosticsService
|
||||
|
||||
|
||||
@@ -55,7 +53,7 @@ async def test_parse_logs_basic(temp_log_file, sample_log_content):
|
||||
events = await service._parse_logs(today, tomorrow)
|
||||
|
||||
# Проверяем что нашлись все события
|
||||
assert len(events) >= 6, f"Expected at least 6 events, found {len(events)}"
|
||||
assert len(events) >= 6, f'Expected at least 6 events, found {len(events)}'
|
||||
|
||||
# Проверяем типы событий
|
||||
event_types = [e.event_type for e in events]
|
||||
@@ -85,18 +83,18 @@ async def test_analyze_period_with_issues(temp_log_file, sample_log_content):
|
||||
# Проверяем статистику
|
||||
# Примечание: code_found не имеет telegram_id, поэтому total_link_clicks будет 0
|
||||
# Это нормально - мы считаем только события с telegram_id
|
||||
assert report.total_codes_applied >= 1, "Should have applied codes"
|
||||
assert report.total_codes_applied >= 1, 'Should have applied codes'
|
||||
|
||||
# Проверяем что нашлись проблемные случаи
|
||||
# (987654321 применил код, но не завершил регистрацию)
|
||||
assert 987654321 in report.users_applied_no_registration, \
|
||||
f"Expected 987654321 in problems, got: {report.users_applied_no_registration}"
|
||||
f'Expected 987654321 in problems, got: {report.users_applied_no_registration}'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_empty_log_file(temp_log_file):
|
||||
"""Тест работы с пустым лог-файлом."""
|
||||
temp_log_file.write_text("")
|
||||
temp_log_file.write_text('')
|
||||
|
||||
service = ReferralDiagnosticsService(log_path=str(temp_log_file))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user