Files
ajurna a7e9bd0743 **Replace Flake8 with Ruff, refactor type hints, and enhance archive processing logic**
- Removed `flake8` and `flake8-annotations` from dependencies, replaced by `ruff` for linting.
- Introduced cleaner type hinting and modern Python annotations (PEP 604 style) across multiple modules.
- Moved archive processing to a dedicated helper (`comic.archives`) for improved maintainability.
- Updated and simplified logic for archive file retrieval, directory cleaning, and user access validation.
- Improved error handling and added support for user classification restrictions in API responses.
2026-10-13 12:07:47 +01:00

49 lines
1.7 KiB
Python

"""Shared fixtures for the test suite."""
from pathlib import Path
import pytest
from comic import models
from comic.tests.factories import make_cbz
@pytest.fixture()
def comic_volume(settings, tmp_path) -> Path:
"""Point COMIC_BOOK_VOLUME at an empty temporary directory."""
settings.COMIC_BOOK_VOLUME = tmp_path
return tmp_path
@pytest.fixture()
def admin_user(db) -> models.User:
return models.User.objects.create_superuser('admin', 'admin@example.com', 'password12345')
@pytest.fixture()
def reader_user(db) -> models.User:
"""A normal user, whose reading allowance defaults to the highest rating."""
return models.User.objects.create_user('reader', 'reader@example.com', 'password12345')
@pytest.fixture()
def restricted_user(db) -> models.User:
"""A user whose allowance is G, so anything rated above G is blocked."""
user = models.User.objects.create_user('restricted', 'restricted@example.com', 'password12345')
models.UserMisc.objects.create(user=user, allowed_to_read=models.Directory.Classification.C_G)
return user
@pytest.fixture()
def rated_directory(db) -> models.Directory:
return models.Directory.objects.create(name='Rated', classification=models.Directory.Classification.C_18)
@pytest.fixture()
def book(db, comic_volume: Path, rated_directory: models.Directory) -> models.ComicBook:
"""A book with a three page archive inside an 18 rated directory."""
directory_path = comic_volume / rated_directory.name
directory_path.mkdir(parents=True, exist_ok=True)
make_cbz(directory_path / 'issue.cbz', pages=3)
return models.ComicBook.objects.create(file_name='issue.cbz', directory=rated_directory, page_count=3)