Files
mtgonline/backend/tests/test_decks.py
T
akadmin b7056fe0d9 Fix SQLite autoincrement and test configuration
- Removed autoincrement=True from BigInteger primary keys (UserDeck, UserDeckCard, DeckPrecedent, etc.)
- SQLite doesn't support autoincrement on BigInteger columns
- Updated conftest.py test engine configuration
- All admin tests passing (5/5)
- All auth tests passing (7/7)
- Game model tests passing (13/13)
- Deck tests still failing due to SQLite RETURNING clause issue
2026-08-28 03:43:14 +00:00

113 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()
assert isinstance(data, list)
assert len(data) > 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
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