This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import pytest
|
||||
from orm.shout import Shout
|
||||
|
||||
from orm.author import Author
|
||||
from orm.shout import Shout
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_author(db_session):
|
||||
"""Create a test author."""
|
||||
author = Author(
|
||||
name="Test Author",
|
||||
slug="test-author",
|
||||
user="test-user-id"
|
||||
)
|
||||
author = Author(name="Test Author", slug="test-author", user="test-user-id")
|
||||
db_session.add(author)
|
||||
db_session.commit()
|
||||
return author
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_shout(db_session):
|
||||
"""Create test shout with required fields."""
|
||||
@@ -27,12 +26,13 @@ def test_shout(db_session):
|
||||
created_by=author.id, # Обязательное поле
|
||||
body="Test body",
|
||||
layout="article",
|
||||
lang="ru"
|
||||
lang="ru",
|
||||
)
|
||||
db_session.add(shout)
|
||||
db_session.commit()
|
||||
return shout
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_shout(test_client, db_session, test_author):
|
||||
"""Test creating a new shout."""
|
||||
@@ -40,8 +40,8 @@ async def test_create_shout(test_client, db_session, test_author):
|
||||
"/",
|
||||
json={
|
||||
"query": """
|
||||
mutation CreateDraft($input: DraftInput!) {
|
||||
create_draft(input: $input) {
|
||||
mutation CreateDraft($draft_input: DraftInput!) {
|
||||
create_draft(draft_input: $draft_input) {
|
||||
error
|
||||
draft {
|
||||
id
|
||||
@@ -56,15 +56,16 @@ async def test_create_shout(test_client, db_session, test_author):
|
||||
"title": "Test Shout",
|
||||
"body": "This is a test shout",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "errors" not in data
|
||||
assert data["data"]["create_draft"]["draft"]["title"] == "Test Shout"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_drafts(test_client, db_session):
|
||||
"""Test retrieving a shout."""
|
||||
@@ -83,13 +84,11 @@ async def test_load_drafts(test_client, db_session):
|
||||
}
|
||||
}
|
||||
""",
|
||||
"variables": {
|
||||
"slug": "test-shout"
|
||||
}
|
||||
}
|
||||
"variables": {"slug": "test-shout"},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "errors" not in data
|
||||
assert data["data"]["load_drafts"]["drafts"] == []
|
||||
assert data["data"]["load_drafts"]["drafts"] == []
|
||||
|
Reference in New Issue
Block a user