mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-23 03:27:14 -04:00
Update
This commit is contained in:
parent
06335058f3
commit
36fd27c83c
17 changed files with 738 additions and 212 deletions
|
@ -130,13 +130,13 @@ def test_sample_config_data_fields(sample_config_data):
|
|||
assert sample_config_data.conversion == test_config.conversion
|
||||
|
||||
|
||||
def test_config_save_file_called_on_del(sample_config, mocker):
|
||||
sample_config.file.set_modified()
|
||||
mockf = mocker.Mock()
|
||||
|
||||
sample_config.save_file = mockf
|
||||
sample_config.__del__()
|
||||
mockf.assert_called_once()
|
||||
# def test_config_save_file_called_on_del(sample_config, mocker):
|
||||
# sample_config.file.set_modified()
|
||||
# mockf = mocker.Mock()
|
||||
#
|
||||
# sample_config.save_file = mockf
|
||||
# sample_config.__del__()
|
||||
# mockf.assert_called_once()
|
||||
|
||||
|
||||
def test_config_update_on_save():
|
||||
|
@ -152,17 +152,17 @@ def test_config_update_on_save():
|
|||
assert conf2.session.downloads.folder == "new_folder"
|
||||
|
||||
|
||||
def test_config_update_on_del():
|
||||
tmp_config_path = "tests/config2.toml"
|
||||
shutil.copy(SAMPLE_CONFIG, tmp_config_path)
|
||||
conf = Config(tmp_config_path)
|
||||
conf.file.downloads.folder = "new_folder"
|
||||
conf.file.set_modified()
|
||||
del conf
|
||||
conf2 = Config(tmp_config_path)
|
||||
os.remove(tmp_config_path)
|
||||
|
||||
assert conf2.session.downloads.folder == "new_folder"
|
||||
# def test_config_update_on_del():
|
||||
# tmp_config_path = "tests/config2.toml"
|
||||
# shutil.copy(SAMPLE_CONFIG, tmp_config_path)
|
||||
# conf = Config(tmp_config_path)
|
||||
# conf.file.downloads.folder = "new_folder"
|
||||
# conf.file.set_modified()
|
||||
# del conf
|
||||
# conf2 = Config(tmp_config_path)
|
||||
# os.remove(tmp_config_path)
|
||||
#
|
||||
# assert conf2.session.downloads.folder == "new_folder"
|
||||
|
||||
|
||||
def test_config_dont_update_without_set_modified():
|
||||
|
|
70
tests/test_qobuz_client.py
Normal file
70
tests/test_qobuz_client.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
import asyncio
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from util import afor, arun
|
||||
|
||||
from streamrip.config import Config
|
||||
from streamrip.downloadable import BasicDownloadable
|
||||
from streamrip.exceptions import MissingCredentials
|
||||
from streamrip.qobuz_client import QobuzClient
|
||||
|
||||
logger = logging.getLogger("streamrip")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config():
|
||||
c = Config.defaults()
|
||||
c.session.qobuz.email_or_userid = os.environ["QOBUZ_EMAIL"]
|
||||
c.session.qobuz.password_or_token = hashlib.md5(
|
||||
os.environ["QOBUZ_PASSWORD"].encode("utf-8")
|
||||
).hexdigest()
|
||||
return c
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(config):
|
||||
c = QobuzClient(config) # type: ignore
|
||||
arun(c.login())
|
||||
return c
|
||||
|
||||
|
||||
def test_client_raises_missing_credentials():
|
||||
c = Config.defaults()
|
||||
with pytest.raises(MissingCredentials):
|
||||
arun(QobuzClient(c).login())
|
||||
|
||||
|
||||
def test_client_get_metadata(client):
|
||||
meta = arun(client.get_metadata("lzpf67e8f4h1a", "album"))
|
||||
assert meta["title"] == "I Killed Your Dog"
|
||||
assert len(meta["tracks"]["items"]) == 16
|
||||
assert meta["maximum_bit_depth"] == 24
|
||||
|
||||
|
||||
def test_client_get_downloadable(client):
|
||||
d = arun(client.get_downloadable("19512574", 3))
|
||||
assert isinstance(d, BasicDownloadable)
|
||||
assert d.extension == "flac"
|
||||
assert isinstance(d.url, str)
|
||||
assert "https://" in d.url
|
||||
|
||||
|
||||
def test_client_search_limit(client):
|
||||
res = client.search("rumours", "album", limit=5)
|
||||
total = 0
|
||||
for r in afor(res):
|
||||
total += len(r["albums"]["items"])
|
||||
assert total == 5
|
||||
|
||||
|
||||
def test_client_search_no_limit(client):
|
||||
res = client.search("rumours", "album", limit=None)
|
||||
correct_total = 0
|
||||
total = 0
|
||||
for r in afor(res):
|
||||
total += len(r["albums"]["items"])
|
||||
correct_total = max(correct_total, r["albums"]["total"])
|
||||
assert total == correct_total
|
Loading…
Add table
Add a link
Reference in a new issue