All checks were successful
Deploy Development / deploy (push) Successful in 36s
Test Suite / pytest-backend (push) Successful in 30s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 8s
Test Suite / playwright-tests (push) Successful in 25s
Test Suite / pytest-backend (pull_request) Successful in 23s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 6s
Test Suite / playwright-tests (pull_request) Successful in 23s
- Incremented application version to 0.8.65 and updated changelog with new features. - Added support for setting default copyright notices for club exercises, allowing users to apply a common copyright notice to linked media assets. - Enhanced error handling to prompt users for copyright information when required. - Updated tests to verify the new copyright handling functionality.
109 lines
3.4 KiB
Python
109 lines
3.4 KiB
Python
"""Vereins-Übung: Copyright-Pflicht für angehängte Archiv-Dateien."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
import routers.exercises as exercises_mod
|
|
from routers.exercises import apply_club_exercise_media_copyright_rules
|
|
|
|
|
|
def test_apply_club_exercise_media_copyright_skips_non_club() -> None:
|
|
apply_club_exercise_media_copyright_rules(object(), 1, "private")
|
|
|
|
|
|
def test_apply_club_exercise_media_copyright_missing_copyright() -> None:
|
|
orig = exercises_mod._fetch_exercise_linked_file_assets
|
|
|
|
def mock_fetch(_cur, eid: int):
|
|
assert eid == 42
|
|
return [
|
|
{
|
|
"id": 10,
|
|
"visibility": "private",
|
|
"club_id": 1,
|
|
"lifecycle_state": "active",
|
|
"copyright_notice": "",
|
|
"original_filename": "x.jpg",
|
|
}
|
|
]
|
|
|
|
exercises_mod._fetch_exercise_linked_file_assets = mock_fetch
|
|
try:
|
|
with pytest.raises(HTTPException) as ei:
|
|
apply_club_exercise_media_copyright_rules(object(), 42, "club")
|
|
assert ei.value.status_code == 422
|
|
d = ei.value.detail
|
|
assert isinstance(d, dict)
|
|
assert d.get("code") == "CLUB_MEDIA_COPYRIGHT_REQUIRED"
|
|
finally:
|
|
exercises_mod._fetch_exercise_linked_file_assets = orig
|
|
|
|
|
|
def test_apply_club_exercise_media_copyright_ok() -> None:
|
|
orig = exercises_mod._fetch_exercise_linked_file_assets
|
|
|
|
def mock_fetch(_cur, _eid: int):
|
|
return [
|
|
{
|
|
"id": 10,
|
|
"visibility": "private",
|
|
"club_id": 1,
|
|
"lifecycle_state": "active",
|
|
"copyright_notice": "© Verein 2026",
|
|
"original_filename": "x.jpg",
|
|
}
|
|
]
|
|
|
|
exercises_mod._fetch_exercise_linked_file_assets = mock_fetch
|
|
try:
|
|
apply_club_exercise_media_copyright_rules(object(), 42, "club")
|
|
finally:
|
|
exercises_mod._fetch_exercise_linked_file_assets = orig
|
|
|
|
|
|
def test_apply_club_exercise_media_copyright_applies_default() -> None:
|
|
"""Nach Bestätigung setzt der Client default_club_media_copyright — Backend schreibt auf Assets."""
|
|
orig_fetch = exercises_mod._fetch_exercise_linked_file_assets
|
|
calls = {"n": 0}
|
|
|
|
def mock_fetch(_cur, _eid: int):
|
|
calls["n"] += 1
|
|
if calls["n"] == 1:
|
|
return [
|
|
{
|
|
"id": 10,
|
|
"visibility": "private",
|
|
"club_id": 1,
|
|
"lifecycle_state": "active",
|
|
"copyright_notice": "",
|
|
"original_filename": "x.jpg",
|
|
}
|
|
]
|
|
return [
|
|
{
|
|
"id": 10,
|
|
"visibility": "private",
|
|
"club_id": 1,
|
|
"lifecycle_state": "active",
|
|
"copyright_notice": "© Testverein",
|
|
"original_filename": "x.jpg",
|
|
}
|
|
]
|
|
|
|
class MockCur:
|
|
def execute(self, *args, **kwargs):
|
|
pass
|
|
|
|
exercises_mod._fetch_exercise_linked_file_assets = mock_fetch
|
|
try:
|
|
apply_club_exercise_media_copyright_rules(
|
|
MockCur(),
|
|
42,
|
|
"club",
|
|
default_club_media_copyright="© Testverein",
|
|
)
|
|
assert calls["n"] == 2
|
|
finally:
|
|
exercises_mod._fetch_exercise_linked_file_assets = orig_fetch
|