Files
shelfmark/tests/conftest.py
Alex a99dc1501d Prowlarr and IRC sources, Google Books, book series support + more (#361)
## Headline features 

### Prowlarr plugin - search trackers and download usenet/torrent books

- Search any usenet/torrent tracker via Prowlarr, returns books within
Universal search
- Configure download clients in the app settings (Qbittorrent, Deluge,
Transmission, NZBget, SABnzbd)
- Unified download and file handling within the app, same as AA. 

### IRC plugin 
- Search IRCHighway #ebooks channel for books and download right in the
app.
- No setup needed
- Credit to OpenBooks for the broad idea and inspiration for best
practices for ebook-specific search and download.

### Google Books Metadata Provider
- Create a Google Cloud API key and use Google Books as a metadata
provider
- Not the best source (Hardcover is still recommended), but another
option and further redundancy for universal search

### Book series support
  - New "Series" search field in Hardcover provider
  - "Series order" sort option - lists books in reading order
  - "View Series" button in book details modal to search the full series
  - Series info display (e.g., "3 of 12 in The Wheel of Time")

## Others: 

- Better format filtering, helpful errors when formats rejected (e.g.,
"Found 3 ebooks but format not supported (.pdf). Enable in Settings >
Formats."
- Directory processing - Handles multi-file torrent/usenet downloads
properly
- Expand search toggle - Skip ISBN search to find more editions
- Filtered authors - Uses primary authors only (excludes
translators/narrators) for better search results
- Language multi-select - Filter releases by multiple languages

 Docker / Build / Testing

  - pip cache mounts - Faster Docker builds via BuildKit cache
  - npm cache mounts - Faster frontend builds
  - APT cleanup - Smaller final image size
  - Added make restart command for quick restarts without rebuild
- New pytest-based test framework with proper configuration
(pyproject.toml)
- Unit tests for all download clients (qBittorrent, Transmission,
Deluge, NZBGet, SABnzbd)
  - Bencode parsing tests
  - Cache tests
  - Integration tests for Prowlarr handler
  - E2E test framework
2025-12-27 14:59:06 +00:00

87 lines
2.6 KiB
Python

"""
Pytest configuration and shared fixtures.
"""
import os
import sys
import tempfile
# Set environment variables BEFORE importing the application
# These override the defaults that try to use system paths like /var/log
_temp_base = tempfile.mkdtemp(prefix="cwabd_test_")
# LOG_ROOT is the base - LOG_DIR is computed as LOG_ROOT / "cwa-book-downloader"
# So we set LOG_ROOT to our temp directory to get LOG_DIR = _temp_base/cwa-book-downloader
os.environ["LOG_ROOT"] = _temp_base
os.environ["CONFIG_DIR"] = os.path.join(_temp_base, "config")
os.environ["INGEST_DIR"] = os.path.join(_temp_base, "ingest")
os.environ["TMP_DIR"] = os.path.join(_temp_base, "tmp")
# Create the directories that will be used
os.makedirs(os.path.join(_temp_base, "cwa-book-downloader"), exist_ok=True) # LOG_DIR
os.makedirs(os.path.join(_temp_base, "config"), exist_ok=True)
os.makedirs(os.path.join(_temp_base, "ingest"), exist_ok=True)
os.makedirs(os.path.join(_temp_base, "tmp"), exist_ok=True)
# Add the project root to Python path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pytest
@pytest.fixture
def sample_prowlarr_result():
"""Sample Prowlarr API search result."""
return {
"guid": "abc123-guid",
"title": "The Great Book by Author Name.epub",
"indexer": "MyIndexer",
"protocol": "torrent",
"size": 5242880, # 5 MB
"downloadUrl": "magnet:?xt=urn:btih:abc123",
"infoUrl": "https://example.com/book/123",
"seeders": 10,
"leechers": 2,
"publishDate": "2024-01-15T12:00:00Z",
"categories": [{"id": 7020, "name": "Books/EBook"}],
"indexerId": 1,
}
@pytest.fixture
def sample_nzb_result():
"""Sample Prowlarr API NZB result."""
return {
"guid": "nzb456-guid",
"title": "Another Book [PDF] by Writer",
"indexer": "NZBIndexer",
"protocol": "usenet",
"size": 10485760, # 10 MB
"downloadUrl": "https://example.com/download.nzb",
"infoUrl": "https://example.com/nzb/456",
"grabs": 50,
"publishDate": "2024-02-20T10:30:00Z",
"categories": [{"id": 7020, "name": "Books/EBook"}],
"indexerId": 2,
}
@pytest.fixture
def mock_config(monkeypatch):
"""Fixture to mock config values."""
config_values = {}
def mock_get(key, default=""):
return config_values.get(key, default)
def set_config(key, value):
config_values[key] = value
# Create a mock config module
class MockConfig:
get = staticmethod(mock_get)
set = staticmethod(set_config)
_values = config_values
return MockConfig