Files
cbwebreader/comic/tests/test_scan_command.py
T
ajurna cc557543c5 **Add Vitest support and migrate frontend tests**
- Added Vitest configuration (`vitest.config.mjs`) for frontend unit testing with a `jsdom` environment.
- Migrated and rewrote key frontend tests (`api.test.js`, `comiclist.test.js`, `comicreader.test.js`, `historytable.test.js`, `router.test.js`, `store.test.js`) to Vitest, improving maintainability.
- Removed `tsconfig.json` and related TypeScript loaders from `webpack` configurations (`webpack.dev.js`, `webpack.prod.js`).
- Adjusted `eslint.config.mjs` to support Vitest tests.
- Updated `package-lock.json` to include Vitest, test utilities (`jsdom`, `@vue/test-utils`), and other associated packages.
- Updated Nginx configuration for better compression on assets (`gzip` adjustments).
- Enhanced `entrypoint.sh` to include first-run library indexing (`--if-empty` argument).
- Simplified the `scan_comics` command with a dedicated test for empty database scans.

This transition improves testing workflows and backend/frontend synergy while removing unused TypeScript dependencies.
2026-10-14 10:07:14 +01:00

57 lines
1.8 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_if_empty_scans_an_empty_database(comic_volume: Path) -> None:
make_cbz(comic_volume / 'issue.cbz', pages=1)
call_command('scan_comics', if_empty=True)
assert models.ComicBook.objects.count() == 1
@pytest.mark.django_db
def test_scan_if_empty_skips_when_books_already_exist(comic_volume: Path) -> None:
"""Files added while the container was down are left to the cron scan."""
make_cbz(comic_volume / 'issue.cbz', pages=1)
call_command('scan_comics')
make_cbz(comic_volume / 'later.cbz', pages=1)
call_command('scan_comics', if_empty=True)
assert models.ComicBook.objects.count() == 1
call_command('scan_comics')
assert models.ComicBook.objects.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