v1.0
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixtures():
|
||||
return Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def media_root(tmp_path_factory):
|
||||
return tmp_path_factory.mktemp('media')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def main_args(media_root, fixtures):
|
||||
return {
|
||||
'verbose': True,
|
||||
'log_level': 'DEBUG',
|
||||
'media_root': media_root,
|
||||
'downloads': fixtures / "downloads",
|
||||
'config_file': fixtures / 'bandcamp-importer.conf',
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_env(monkeypatch, fixtures, media_root):
|
||||
if 'LOG_LEVEL' in os.environ:
|
||||
del os.environ['LOG_LEVEL']
|
||||
+1
@@ -0,0 +1 @@
|
||||
downloads/artist - title.zip
|
||||
@@ -1,7 +0,0 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_tests_are_implemented():
|
||||
print("Yyou have not implemented any tests yet.")
|
||||
assert False
|
||||
@@ -1,8 +1,50 @@
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
import typer
|
||||
|
||||
from bandcamp_importer import cli
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_tests_are_implemented():
|
||||
assert cli.main()
|
||||
@pytest.fixture
|
||||
def context():
|
||||
return MagicMock(spec=typer.Context, args=[], invoked_subcommand=None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("files, downloads, expected", [
|
||||
([], None, [
|
||||
"artist",
|
||||
"artist/album",
|
||||
"artist/album/one.mp3",
|
||||
"artist/album/two.m4a",
|
||||
"artist/album/cover.jpg",
|
||||
]),
|
||||
(["invalid_filename.zip"], None, []),
|
||||
(["does_not_exist.zip"], None, []),
|
||||
(["invalid - zipfile_format.zip"], None, []),
|
||||
])
|
||||
def test_import_album(context, main_args, media_root, fixtures, files, downloads, expected):
|
||||
context.configure_mock(args=[fixtures / filename for filename in files])
|
||||
cli.main(context, **main_args)
|
||||
results = sorted([str(Path(p).relative_to(media_root)) for p in media_root.rglob("*")])
|
||||
assert results == sorted(expected)
|
||||
|
||||
|
||||
def test_imports_are_idempotent(context, main_args, media_root, fixtures):
|
||||
cli.main(context, **main_args)
|
||||
cover = media_root / 'artist' / 'album' / 'cover.jpg'
|
||||
mtime = cover.stat().st_mtime
|
||||
cli.main(context, **main_args)
|
||||
assert cover.stat().st_mtime == mtime
|
||||
|
||||
|
||||
def test_main(context, main_args):
|
||||
context.configure_mock(invoked_subcommand=None)
|
||||
if 'LOG_LEVEL' in os.environ:
|
||||
del os.environ['LOG_LEVEL']
|
||||
cli.main(context, **main_args)
|
||||
assert cli.app_state['verbose'] is True
|
||||
assert os.environ['LOG_LEVEL'] == 'INFO'
|
||||
|
||||
Reference in New Issue
Block a user