mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-25 04:24:49 -04:00
Update tests
This commit is contained in:
parent
fa65929c97
commit
1704406cdf
1 changed files with 25 additions and 11 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -12,9 +13,22 @@ from streamrip.exceptions import MissingCredentialsError
|
||||||
logger = logging.getLogger("streamrip")
|
logger = logging.getLogger("streamrip")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture(scope="session")
|
||||||
def client(qobuz_client):
|
def qobuz_client():
|
||||||
return qobuz_client
|
config = Config.defaults()
|
||||||
|
config.session.qobuz.email_or_userid = os.environ["QOBUZ_EMAIL"]
|
||||||
|
config.session.qobuz.password_or_token = hashlib.md5(
|
||||||
|
os.environ["QOBUZ_PASSWORD"].encode("utf-8"),
|
||||||
|
).hexdigest()
|
||||||
|
if "QOBUZ_APP_ID" in os.environ and "QOBUZ_SECRETS" in os.environ:
|
||||||
|
config.session.qobuz.app_id = os.environ["QOBUZ_APP_ID"]
|
||||||
|
config.session.qobuz.secrets = os.environ["QOBUZ_SECRETS"].split(",")
|
||||||
|
client = QobuzClient(config)
|
||||||
|
arun(client.login())
|
||||||
|
|
||||||
|
yield client
|
||||||
|
|
||||||
|
arun(client.session.close())
|
||||||
|
|
||||||
|
|
||||||
def test_client_raises_missing_credentials():
|
def test_client_raises_missing_credentials():
|
||||||
|
@ -26,8 +40,8 @@ def test_client_raises_missing_credentials():
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
||||||
)
|
)
|
||||||
def test_client_get_metadata(client):
|
def test_client_get_metadata(qobuz_client):
|
||||||
meta = arun(client.get_metadata("s9nzkwg2rh1nc", "album"))
|
meta = arun(qobuz_client.get_metadata("s9nzkwg2rh1nc", "album"))
|
||||||
assert meta["title"] == "I Killed Your Dog"
|
assert meta["title"] == "I Killed Your Dog"
|
||||||
assert len(meta["tracks"]["items"]) == 16
|
assert len(meta["tracks"]["items"]) == 16
|
||||||
assert meta["maximum_bit_depth"] == 24
|
assert meta["maximum_bit_depth"] == 24
|
||||||
|
@ -36,8 +50,8 @@ def test_client_get_metadata(client):
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
||||||
)
|
)
|
||||||
def test_client_get_downloadable(client):
|
def test_client_get_downloadable(qobuz_client):
|
||||||
d = arun(client.get_downloadable("19512574", 3))
|
d = arun(qobuz_client.get_downloadable("19512574", 3))
|
||||||
assert isinstance(d, BasicDownloadable)
|
assert isinstance(d, BasicDownloadable)
|
||||||
assert d.extension == "flac"
|
assert d.extension == "flac"
|
||||||
assert isinstance(d.url, str)
|
assert isinstance(d.url, str)
|
||||||
|
@ -47,8 +61,8 @@ def test_client_get_downloadable(client):
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
||||||
)
|
)
|
||||||
def test_client_search_limit(client):
|
def test_client_search_limit(qobuz_client):
|
||||||
res = client.search("album", "rumours", limit=5)
|
res = qobuz_client.search("album", "rumours", limit=5)
|
||||||
total = 0
|
total = 0
|
||||||
for r in arun(res):
|
for r in arun(res):
|
||||||
total += len(r["albums"]["items"])
|
total += len(r["albums"]["items"])
|
||||||
|
@ -58,9 +72,9 @@ def test_client_search_limit(client):
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
|
||||||
)
|
)
|
||||||
def test_client_search_no_limit(client):
|
def test_client_search_no_limit(qobuz_client):
|
||||||
# Setting no limit has become impossible because `limit: int` now
|
# Setting no limit has become impossible because `limit: int` now
|
||||||
res = client.search("album", "rumours", limit=10000)
|
res = qobuz_client.search("album", "rumours", limit=10000)
|
||||||
correct_total = 0
|
correct_total = 0
|
||||||
total = 0
|
total = 0
|
||||||
for r in arun(res):
|
for r in arun(res):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue