mirror of
https://github.com/ajurna/cbwebreader.git
synced 2026-11-02 10:36:55 +00:00
- Added a new `scan_directory` task to enable folder scans as asynchronous tasks while maintaining compatibility with the immediate backend. - Introduced the `reconcile` function, replacing `generate_directory` for improved separation of concerns between database writes and read operations. - Established a unique constraint on `Directory` (`one_directory_name_per_parent`) to prevent duplicate directories under the same parent. - Added a "Scan" button to the frontend for re-reading folders from disk, along with new task invocation endpoints in the API. - Updated tests across modules to validate the new `scan_directory` task, unique constraints, and database indexing logic. - Improved cleanup logic for stale files, directories, and thumbnails to handle concurrent operations efficiently. - Simplified `scan_comics` management command by removing user dependency and aligning it with the new `reconcile` function. - Enhanced frontend components (`TheComicReader`, `TheComicList`, and others) to include lifecycle method cleanups, prevent memory leaks, and handle task-based scans.
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
"""Tests for the scan_comics management command."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from django.core.management import call_command
|
|
|
|
from comic import models
|
|
from comic.tests.factories import make_cbz
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_scan_indexes_nested_directories(comic_volume: Path, reader_user) -> None:
|
|
nested = comic_volume / 'Series' / 'Volume 1'
|
|
nested.mkdir(parents=True)
|
|
make_cbz(nested / 'issue.cbz', pages=2)
|
|
|
|
call_command('scan_comics')
|
|
|
|
directory = models.Directory.objects.get(name='Volume 1', parent__name='Series')
|
|
book = models.ComicBook.objects.get(file_name='issue.cbz', directory=directory)
|
|
assert book.page_count == 2
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_scan_runs_without_any_user(comic_volume: Path) -> None:
|
|
"""The command no longer needs a user, because statuses are created when a book is read."""
|
|
make_cbz(comic_volume / 'issue.cbz', pages=1)
|
|
|
|
call_command('scan_comics')
|
|
|
|
assert models.ComicBook.objects.count() == 1
|
|
assert models.ComicStatus.objects.count() == 0
|