- Fixed conftest.py: Use execution_options for implicit_returning (SQLAlchemy 2.0) - Fixed models.py: Changed UserDeck.updated_at onupdate from func.now() to datetime.now - All 5 deck tests now pass - Full suite: 26 passed, 2 failed (pre-existing game model issues)
114 lines
3.5 KiB
Python
114 lines
3.5 KiB
Python
"""
|
|
Tests for deck management endpoints.
|
|
"""
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.models.models import DecklistFile, DecklistFolder
|
|
from app.core.security import hash_password
|
|
|
|
|
|
class TestDeckManagement:
|
|
"""Test deck management endpoints."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_deck(self, client: AsyncClient, auth_headers: dict):
|
|
"""Test creating a new deck."""
|
|
response = await client.post(
|
|
"/decks/",
|
|
json={
|
|
"name": "Test Deck",
|
|
"format": "standard",
|
|
},
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 201
|
|
data = response.json()
|
|
assert data["name"] == "Test Deck"
|
|
assert data["format"] == "standard"
|
|
assert "id" in data
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_decks(self, client: AsyncClient, auth_headers: dict):
|
|
"""Test listing decks."""
|
|
# Create a deck first
|
|
await client.post(
|
|
"/decks/",
|
|
json={
|
|
"name": "List Test Deck",
|
|
"format": "standard",
|
|
},
|
|
headers=auth_headers,
|
|
)
|
|
|
|
# List decks
|
|
response = await client.get("/decks/", headers=auth_headers)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
# API returns paginated response with 'decks' key
|
|
assert 'decks' in data
|
|
assert len(data['decks']) > 0
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_deck(self, client: AsyncClient, auth_headers: dict):
|
|
"""Test getting a specific deck."""
|
|
# Create a deck first
|
|
create_response = await client.post(
|
|
"/decks/",
|
|
json={
|
|
"name": "Get Test Deck",
|
|
"format": "standard",
|
|
},
|
|
headers=auth_headers,
|
|
)
|
|
deck_id = create_response.json()["id"]
|
|
|
|
# Get deck
|
|
response = await client.get(f"/decks/{deck_id}", headers=auth_headers)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "Get Test Deck"
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_deck(self, client: AsyncClient, auth_headers: dict):
|
|
"""Test updating a deck."""
|
|
# Create a deck first
|
|
create_response = await client.post(
|
|
"/decks/",
|
|
json={
|
|
"name": "Update Test Deck",
|
|
"format": "standard",
|
|
},
|
|
headers=auth_headers,
|
|
)
|
|
deck_id = create_response.json()["id"]
|
|
|
|
# Update deck name
|
|
response = await client.patch(
|
|
f"/decks/{deck_id}",
|
|
json={"name": "Updated Deck Name"},
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "Updated Deck Name"
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_deck(self, client: AsyncClient, auth_headers: dict):
|
|
"""Test deleting a deck."""
|
|
# Create a deck first
|
|
create_response = await client.post(
|
|
"/decks/",
|
|
json={
|
|
"name": "Delete Test Deck",
|
|
"format": "standard",
|
|
},
|
|
headers=auth_headers,
|
|
)
|
|
deck_id = create_response.json()["id"]
|
|
|
|
# Delete deck
|
|
response = await client.delete(f"/decks/{deck_id}", headers=auth_headers)
|
|
assert response.status_code == 200
|