mirror of
https://github.com/wizarrrr/wizarr.git
synced 2025-12-23 23:59:23 -05:00
Refactor test fixtures to include session parameter for improved database handling
This commit is contained in:
@@ -18,6 +18,7 @@ def admin_user(app):
|
||||
"""Create an admin account for authenticated requests."""
|
||||
with app.app_context():
|
||||
created = False
|
||||
previous_hash = None
|
||||
admin = AdminAccount.query.filter_by(username="testadmin").first()
|
||||
if not admin:
|
||||
admin = AdminAccount(username="testadmin")
|
||||
@@ -25,10 +26,20 @@ def admin_user(app):
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
created = True
|
||||
else:
|
||||
previous_hash = admin.password_hash
|
||||
admin.set_password("TestPass123")
|
||||
db.session.commit()
|
||||
yield admin
|
||||
if created:
|
||||
db.session.delete(admin)
|
||||
db.session.commit()
|
||||
elif previous_hash is not None:
|
||||
# Restore the original password hash so other tests keep their expectations
|
||||
admin = AdminAccount.query.filter_by(username="testadmin").first()
|
||||
if admin:
|
||||
admin.password_hash = previous_hash
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -8,7 +8,7 @@ from app.models import AdminAccount, ApiKey, Library, MediaServer, Settings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_key(app):
|
||||
def api_key(app, session):
|
||||
"""Create a test API key."""
|
||||
with app.app_context():
|
||||
# Create admin account if it doesn't exist
|
||||
@@ -45,7 +45,7 @@ def api_key(app):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_server(app):
|
||||
def test_server(app, session):
|
||||
"""Create a test media server."""
|
||||
with app.app_context():
|
||||
# Create admin account if it doesn't exist
|
||||
|
||||
Reference in New Issue
Block a user