Files
wizarr/tests/test_wizard_step.py
Matthieu B 22d7e5dcc5 fix: resolve test failures and lint issues
- Fix test database isolation by cleaning WizardStep data before tests run
- Remove unused imports and fix import ordering
- Replace setattr with direct attribute assignment
- Use contextlib.suppress for cleaner exception handling
- Fix nested if statement in wizard_export_import.py

Fixes the failing CI checks for PR #817.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-07 15:58:42 +02:00

52 lines
1.4 KiB
Python

import pytest
from sqlalchemy.exc import IntegrityError
from app.extensions import db
from app.models import WizardStep
@pytest.fixture
def session(app):
"""Return a clean database session inside an app context."""
with app.app_context():
# Clean up any existing WizardStep data before the test
db.session.query(WizardStep).delete()
db.session.commit()
yield db.session
# Clean up after the test
db.session.rollback()
def test_create_wizard_step(session):
"""Basic insertion & to_dict serialization work."""
step = WizardStep(
server_type="plex",
position=0,
title="Welcome",
markdown="# Welcome\nSome intro text",
requires=["server_url"],
)
session.add(step)
session.commit()
fetched = WizardStep.query.first()
assert fetched is not None
assert fetched.title == "Welcome"
assert fetched.to_dict() is not None
assert fetched.to_dict()["server_type"] == "plex"
def test_unique_server_position_constraint(session):
"""(server_type, position) must be unique."""
a = WizardStep(server_type="plex", position=1, markdown="a")
b = WizardStep(server_type="plex", position=1, markdown="b")
session.add(a)
session.commit()
session.add(b)
with pytest.raises(IntegrityError):
session.commit() # duplicate position for same server_type