2023-10-21 22:18:06 -04:00
|
|
|
import logging
|
2023-12-27 17:40:51 -05:00
|
|
|
import os
|
2023-10-21 22:18:06 -04:00
|
|
|
|
|
|
|
import pytest
|
2023-12-27 17:40:51 -05:00
|
|
|
from util import arun
|
2023-10-21 22:18:06 -04:00
|
|
|
|
2023-12-26 15:20:34 -05:00
|
|
|
from streamrip.client.downloadable import BasicDownloadable
|
|
|
|
from streamrip.client.qobuz import QobuzClient
|
2023-12-27 17:40:51 -05:00
|
|
|
from streamrip.config import Config
|
|
|
|
from streamrip.exceptions import MissingCredentialsError
|
2023-10-21 22:18:06 -04:00
|
|
|
|
|
|
|
logger = logging.getLogger("streamrip")
|
|
|
|
|
|
|
|
|
2023-12-21 01:21:58 -05:00
|
|
|
@pytest.fixture()
|
2023-10-29 17:42:10 -04:00
|
|
|
def client(qobuz_client):
|
|
|
|
return qobuz_client
|
2023-10-21 22:18:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_client_raises_missing_credentials():
|
|
|
|
c = Config.defaults()
|
2023-12-26 15:20:34 -05:00
|
|
|
with pytest.raises(MissingCredentialsError):
|
2023-10-21 22:18:06 -04:00
|
|
|
arun(QobuzClient(c).login())
|
|
|
|
|
|
|
|
|
2023-12-27 17:40:51 -05:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
|
|
|
)
|
2023-10-21 22:18:06 -04:00
|
|
|
def test_client_get_metadata(client):
|
2023-12-26 17:55:30 -05:00
|
|
|
meta = arun(client.get_metadata("s9nzkwg2rh1nc", "album"))
|
2023-10-21 22:18:06 -04:00
|
|
|
assert meta["title"] == "I Killed Your Dog"
|
|
|
|
assert len(meta["tracks"]["items"]) == 16
|
|
|
|
assert meta["maximum_bit_depth"] == 24
|
|
|
|
|
|
|
|
|
2023-12-27 17:40:51 -05:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
|
|
|
)
|
2023-10-21 22:18:06 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-12-27 17:40:51 -05:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
|
|
|
)
|
2023-10-21 22:18:06 -04:00
|
|
|
def test_client_search_limit(client):
|
2023-12-26 17:55:30 -05:00
|
|
|
res = client.search("album", "rumours", limit=5)
|
2023-10-21 22:18:06 -04:00
|
|
|
total = 0
|
2023-12-26 17:55:30 -05:00
|
|
|
for r in arun(res):
|
2023-10-21 22:18:06 -04:00
|
|
|
total += len(r["albums"]["items"])
|
|
|
|
assert total == 5
|
|
|
|
|
|
|
|
|
2023-12-27 17:40:51 -05:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
|
|
|
)
|
2023-10-21 22:18:06 -04:00
|
|
|
def test_client_search_no_limit(client):
|
2023-12-26 17:55:30 -05:00
|
|
|
# Setting no limit has become impossible because `limit: int` now
|
|
|
|
res = client.search("album", "rumours", limit=10000)
|
2023-10-21 22:18:06 -04:00
|
|
|
correct_total = 0
|
|
|
|
total = 0
|
2023-12-26 17:55:30 -05:00
|
|
|
for r in arun(res):
|
2023-10-21 22:18:06 -04:00
|
|
|
total += len(r["albums"]["items"])
|
|
|
|
correct_total = max(correct_total, r["albums"]["total"])
|
|
|
|
assert total == correct_total
|