Files
core/tests/test_draft_publish_fix.py
Untone 1b25738714
Some checks failed
Deploy on push / deploy (push) Failing after 32s
publish-shout-fix
2025-08-21 12:16:30 +03:00

77 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Тест исправления публикации черновиков.
Проверяет что:
1. Убран недопустимый аргумент 'draft' из создания Shout
2. Draft.shout корректно обновляется после публикации
3. Draft.shout очищается при снятии с публикации
"""
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from orm.draft import Draft
from orm.shout import Shout
from resolvers.draft import create_shout_from_draft
class TestDraftPublishFix:
"""Тесты исправления публикации черновиков."""
def test_create_shout_from_draft_no_draft_argument(self):
"""Тест что create_shout_from_draft не передает недопустимый аргумент 'draft'."""
# Arrange
mock_draft = MagicMock(spec=Draft)
mock_draft.body = "Test body"
mock_draft.slug = "test-slug"
mock_draft.cover = "test-cover.jpg"
mock_draft.cover_caption = "Test caption"
mock_draft.lead = "Test lead"
mock_draft.title = "Test title"
mock_draft.subtitle = "Test subtitle"
mock_draft.layout = "article"
mock_draft.media = []
mock_draft.lang = "ru"
mock_draft.seo = "test-seo"
mock_draft.community = 1
# Act
shout = create_shout_from_draft(None, mock_draft, 1)
# Assert
assert isinstance(shout, Shout)
assert shout.body == "Test body"
assert shout.slug == "test-slug"
assert shout.cover == "test-cover.jpg"
assert shout.cover_caption == "Test caption"
assert shout.lead == "Test lead"
assert shout.title == "Test title"
assert shout.subtitle == "Test subtitle"
assert shout.layout == "article"
assert shout.media == []
assert shout.lang == "ru"
assert shout.seo == "test-seo"
assert shout.created_by == 1
assert shout.community == 1
assert shout.deleted_at is None
# Проверяем что нет поля draft
assert not hasattr(shout, 'draft')
def test_draft_model_has_shout_field(self):
"""Тест что модель Draft имеет поле shout."""
# Arrange & Act
draft = Draft()
# Assert
assert hasattr(draft, 'shout')
assert draft.shout is None
def test_shout_model_does_not_have_draft_field(self):
"""Тест что модель Shout не имеет поля draft."""
# Arrange & Act
shout = Shout()
# Assert
assert not hasattr(shout, 'draft')