grooveondemand/test/test_scanner.py
evilchili 17a6dcb4d2 refactor media module, change --env to --root
This commit moves the media scanner out of the db module and into
a new module, media. We also change the --env parameter to --root,
which takes a path to a directory where the default configuration
and the transcoded media cache will live.
2022-12-31 12:43:48 -08:00

38 lines
1.0 KiB
Python

import pytest
import os
from pathlib import Path
from unittest.mock import MagicMock
from sqlalchemy import func
import groove.exceptions
from groove.media import scanner
from groove.db import track
def test_scanner(monkeypatch, in_memory_db):
def mock_loader(path):
return {
'artist': 'foo',
'title': 'bar',
}
monkeypatch.setattr(scanner.MediaScanner, '_get_tags', MagicMock(side_effect=mock_loader))
test_scanner = scanner.MediaScanner(path=Path('UNKLE'), db=in_memory_db)
# verify all entries are scanned
assert test_scanner.scan() == 1
# readback; verify entries are in the db
query = func.count(track.c.relpath)
query = query.filter(track.c.relpath.ilike('%UNKLE%'))
assert in_memory_db.query(query).scalar() == 1
# verify idempotency
assert test_scanner.scan() == 0
def test_scanner_no_media_root(in_memory_db):
del os.environ['MEDIA_ROOT']
with pytest.raises(groove.exceptions.ConfigurationError):
assert scanner.MediaScanner(path=None, db=in_memory_db)