grooveondemand/test/test_scanner.py

37 lines
1.0 KiB
Python
Raw Normal View History

2022-11-20 16:26:40 -08:00
import pytest
import os
2022-11-20 16:26:40 -08:00
from pathlib import Path
from unittest.mock import MagicMock
from sqlalchemy import func
2022-12-05 01:06:57 -08:00
import groove.exceptions
2022-11-20 16:26:40 -08:00
from groove.db import scanner, track
2022-12-05 01:06:57 -08:00
2022-12-21 15:17:13 -08:00
def test_scanner(monkeypatch, in_memory_db):
2022-11-30 23:42:06 -08:00
def mock_loader(path):
return {
'artist': 'foo',
'title': 'bar',
}
monkeypatch.setattr(scanner.MediaScanner, '_get_tags', MagicMock(side_effect=mock_loader))
2022-12-21 15:17:13 -08:00
test_scanner = scanner.MediaScanner(path=Path('UNKLE'), db=in_memory_db)
2022-11-20 16:26:40 -08:00
# verify all entries are scanned
2022-12-21 15:17:13 -08:00
assert test_scanner.scan() == 1
2022-11-20 16:26:40 -08:00
# readback; verify entries are in the db
query = func.count(track.c.relpath)
2022-12-21 15:17:13 -08:00
query = query.filter(track.c.relpath.ilike('%UNKLE%'))
assert in_memory_db.query(query).scalar() == 1
2022-11-20 16:26:40 -08:00
# verify idempotency
assert test_scanner.scan() == 0
def test_scanner_no_media_root(in_memory_db):
del os.environ['MEDIA_ROOT']
2022-12-05 01:06:57 -08:00
with pytest.raises(groove.exceptions.ConfigurationError):
2022-12-21 15:17:13 -08:00
assert scanner.MediaScanner(path=None, db=in_memory_db)