core/tests/test_reactions.py

69 lines
1.8 KiB
Python
Raw Permalink Normal View History

2025-02-11 09:00:35 +00:00
from datetime import datetime
2025-02-09 19:26:50 +00:00
import pytest
2025-02-11 09:00:35 +00:00
from orm.author import Author
2025-02-11 21:31:18 +00:00
from orm.reaction import ReactionKind
2025-02-09 19:26:50 +00:00
from orm.shout import Shout
2025-02-11 09:00:35 +00:00
2025-02-09 19:26:50 +00:00
@pytest.fixture
def test_setup(db_session):
"""Set up test data."""
now = int(datetime.now().timestamp())
author = Author(name="Test Author", slug="test-author", user="test-user-id")
db_session.add(author)
db_session.flush()
2025-02-11 09:00:35 +00:00
2025-02-09 19:26:50 +00:00
shout = Shout(
2025-02-11 09:00:35 +00:00
title="Test Shout",
2025-02-09 19:26:50 +00:00
slug="test-shout",
created_by=author.id,
body="This is a test shout",
layout="article",
lang="ru",
community=1,
created_at=now,
2025-02-11 09:00:35 +00:00
updated_at=now,
2025-02-09 19:26:50 +00:00
)
db_session.add_all([author, shout])
db_session.commit()
return {"author": author, "shout": shout}
2025-02-11 09:00:35 +00:00
2025-02-09 19:26:50 +00:00
@pytest.mark.asyncio
async def test_create_reaction(test_client, db_session, test_setup):
"""Test creating a reaction on a shout."""
response = test_client.post(
"/",
json={
"query": """
mutation CreateReaction($reaction: ReactionInput!) {
create_reaction(reaction: $reaction) {
error
reaction {
id
kind
body
created_by {
name
}
}
}
}
""",
"variables": {
2025-05-16 06:11:39 +00:00
"reaction": {
"shout": test_setup["shout"].id,
"kind": ReactionKind.LIKE.value,
"body": "Great post!",
}
2025-02-11 09:00:35 +00:00
},
},
2025-02-09 19:26:50 +00:00
)
2025-02-11 09:00:35 +00:00
2025-02-09 19:26:50 +00:00
assert response.status_code == 200
data = response.json()
assert "error" not in data
2025-05-16 06:22:53 +00:00
assert data["data"]["create_reaction"]["reaction"]["kind"] == ReactionKind.LIKE.value