mirror of
https://github.com/wizarrrr/wizarr.git
synced 2026-07-31 23:37:07 -04:00
- Added `identity_resolution.py` for resolving Wizarr users and identities. - Created `ingestion.py` to handle recording and updating activity events. - Introduced `maintenance.py` for cleanup and session management tasks. - Developed `queries.py` for read-oriented operations on activity sessions. - Implemented background tasks in `activity.py` for scheduled maintenance. - Added tests for activity services and blueprint to ensure functionality.
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
from flask import Flask
|
|
from flask_login import LoginManager, UserMixin, login_user
|
|
|
|
from app.activity.api.blueprint import activity_bp
|
|
|
|
|
|
class _TestUser(UserMixin):
|
|
id = "pytest-user"
|
|
|
|
|
|
@pytest.fixture
|
|
def activity_app():
|
|
"""Minimal Flask app with the activity blueprint registered."""
|
|
app = Flask(__name__)
|
|
app.config.update(
|
|
SECRET_KEY="testing-secret",
|
|
TESTING=True,
|
|
)
|
|
|
|
login_manager = LoginManager()
|
|
login_manager.init_app(app)
|
|
login_manager.login_view = "_login_route"
|
|
|
|
@login_manager.user_loader
|
|
def _load_user(user_id): # pragma: no cover - required by flask-login
|
|
if user_id == _TestUser.id:
|
|
return _TestUser()
|
|
return None
|
|
|
|
@app.route("/_login")
|
|
def _login_route():
|
|
login_user(_TestUser())
|
|
return "ok"
|
|
|
|
template_dir = Path(__file__).resolve().parents[2] / "app" / "templates"
|
|
if str(template_dir) not in app.jinja_loader.searchpath:
|
|
app.jinja_loader.searchpath.append(str(template_dir))
|
|
|
|
app.jinja_env.globals.setdefault("_", lambda s, **_: s)
|
|
app.jinja_env.globals.setdefault(
|
|
"ngettext",
|
|
lambda singular, plural, number, **_: singular if number == 1 else plural,
|
|
)
|
|
|
|
app.register_blueprint(activity_bp)
|
|
return app
|
|
|
|
|
|
@pytest.fixture
|
|
def activity_client(activity_app):
|
|
return activity_app.test_client()
|
|
|
|
|
|
@pytest.fixture
|
|
def logged_activity_client(activity_client):
|
|
activity_client.get("/_login")
|
|
return activity_client
|