fix quality code

This commit is contained in:
2026-02-01 23:03:23 +03:00
parent 731e68a597
commit f8962225ee
106 changed files with 8456 additions and 5810 deletions

View File

@@ -5,6 +5,7 @@ from datetime import datetime
from unittest.mock import AsyncMock, Mock
import pytest
from database.models import MessageContentLink, PostContent, TelegramPost
from database.repositories.post_repository import PostRepository
@@ -37,7 +38,7 @@ def sample_telegram_post():
text="Тестовый пост для unit тестов",
author_id=67890,
helper_text_message_id=None,
created_at=int(datetime.now().timestamp())
created_at=int(datetime.now().timestamp()),
)
@@ -49,7 +50,7 @@ def sample_telegram_post_with_helper():
text="Тестовый пост с helper сообщением",
author_id=67890,
helper_text_message_id=99999,
created_at=int(datetime.now().timestamp())
created_at=int(datetime.now().timestamp()),
)
@@ -61,7 +62,7 @@ def sample_telegram_post_no_date():
text="Тестовый пост без даты",
author_id=67890,
helper_text_message_id=None,
created_at=None
created_at=None,
)
@@ -69,19 +70,14 @@ def sample_telegram_post_no_date():
def sample_post_content():
"""Создает тестовый объект PostContent"""
return PostContent(
message_id=12345,
content_name="/path/to/test/file.jpg",
content_type="photo"
message_id=12345, content_name="/path/to/test/file.jpg", content_type="photo"
)
@pytest.fixture
def sample_message_content_link():
"""Создает тестовый объект MessageContentLink"""
return MessageContentLink(
post_id=12345,
message_id=67890
)
return MessageContentLink(post_id=12345, message_id=67890)
@pytest.fixture
@@ -105,11 +101,11 @@ def mock_logger():
@pytest.fixture
def temp_db_file():
"""Создает временный файл БД для интеграционных тестов"""
with tempfile.NamedTemporaryFile(suffix='.db', delete=False) as tmp_file:
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as tmp_file:
db_path = tmp_file.name
yield db_path
# Очищаем временный файл после тестов
try:
os.unlink(db_path)
@@ -132,22 +128,22 @@ def sample_posts_batch():
text="Первый тестовый пост",
author_id=11111,
helper_text_message_id=None,
created_at=int(datetime.now().timestamp())
created_at=int(datetime.now().timestamp()),
),
TelegramPost(
message_id=10002,
text="Второй тестовый пост",
author_id=22222,
helper_text_message_id=None,
created_at=int(datetime.now().timestamp())
created_at=int(datetime.now().timestamp()),
),
TelegramPost(
message_id=10003,
text="Третий тестовый пост",
author_id=33333,
helper_text_message_id=88888,
created_at=int(datetime.now().timestamp())
)
created_at=int(datetime.now().timestamp()),
),
]
@@ -159,7 +155,7 @@ def sample_content_batch():
(10002, "/path/to/video1.mp4", "video"),
(10003, "/path/to/audio1.mp3", "audio"),
(10004, "/path/to/photo2.jpg", "photo"),
(10005, "/path/to/video2.mp4", "video")
(10005, "/path/to/video2.mp4", "video"),
]
@@ -195,19 +191,19 @@ def sample_author_ids():
def mock_sql_queries():
"""Создает мок для SQL запросов"""
return {
'create_tables': [
"create_tables": [
"CREATE TABLE IF NOT EXISTS post_from_telegram_suggest",
"CREATE TABLE IF NOT EXISTS content_post_from_telegram",
"CREATE TABLE IF NOT EXISTS message_link_to_content"
"CREATE TABLE IF NOT EXISTS message_link_to_content",
],
'add_post': "INSERT INTO post_from_telegram_suggest",
'add_post_status': "status",
'update_helper': "UPDATE post_from_telegram_suggest SET helper_text_message_id",
'update_status': "UPDATE post_from_telegram_suggest SET status = ?",
'add_content': "INSERT OR IGNORE INTO content_post_from_telegram",
'add_link': "INSERT OR IGNORE INTO message_link_to_content",
'get_content': "SELECT cpft.content_name, cpft.content_type",
'get_text': "SELECT text FROM post_from_telegram_suggest",
'get_ids': "SELECT mltc.message_id",
'get_author': "SELECT author_id FROM post_from_telegram_suggest"
"add_post": "INSERT INTO post_from_telegram_suggest",
"add_post_status": "status",
"update_helper": "UPDATE post_from_telegram_suggest SET helper_text_message_id",
"update_status": "UPDATE post_from_telegram_suggest SET status = ?",
"add_content": "INSERT OR IGNORE INTO content_post_from_telegram",
"add_link": "INSERT OR IGNORE INTO message_link_to_content",
"get_content": "SELECT cpft.content_name, cpft.content_type",
"get_text": "SELECT text FROM post_from_telegram_suggest",
"get_ids": "SELECT mltc.message_id",
"get_author": "SELECT author_id FROM post_from_telegram_suggest",
}