Skip to content

Commit 1704406

Browse files
committed
Update tests
1 parent fa65929 commit 1704406

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

tests/test_qobuz_client.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import logging
23
import os
34

@@ -12,9 +13,22 @@
1213
logger = logging.getLogger("streamrip")
1314

1415

15-
@pytest.fixture()
16-
def client(qobuz_client):
17-
return qobuz_client
16+
@pytest.fixture(scope="session")
17+
def qobuz_client():
18+
config = Config.defaults()
19+
config.session.qobuz.email_or_userid = os.environ["QOBUZ_EMAIL"]
20+
config.session.qobuz.password_or_token = hashlib.md5(
21+
os.environ["QOBUZ_PASSWORD"].encode("utf-8"),
22+
).hexdigest()
23+
if "QOBUZ_APP_ID" in os.environ and "QOBUZ_SECRETS" in os.environ:
24+
config.session.qobuz.app_id = os.environ["QOBUZ_APP_ID"]
25+
config.session.qobuz.secrets = os.environ["QOBUZ_SECRETS"].split(",")
26+
client = QobuzClient(config)
27+
arun(client.login())
28+
29+
yield client
30+
31+
arun(client.session.close())
1832

1933

2034
def test_client_raises_missing_credentials():
@@ -26,8 +40,8 @@ def test_client_raises_missing_credentials():
2640
@pytest.mark.skipif(
2741
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
2842
)
29-
def test_client_get_metadata(client):
30-
meta = arun(client.get_metadata("s9nzkwg2rh1nc", "album"))
43+
def test_client_get_metadata(qobuz_client):
44+
meta = arun(qobuz_client.get_metadata("s9nzkwg2rh1nc", "album"))
3145
assert meta["title"] == "I Killed Your Dog"
3246
assert len(meta["tracks"]["items"]) == 16
3347
assert meta["maximum_bit_depth"] == 24
@@ -36,8 +50,8 @@ def test_client_get_metadata(client):
3650
@pytest.mark.skipif(
3751
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
3852
)
39-
def test_client_get_downloadable(client):
40-
d = arun(client.get_downloadable("19512574", 3))
53+
def test_client_get_downloadable(qobuz_client):
54+
d = arun(qobuz_client.get_downloadable("19512574", 3))
4155
assert isinstance(d, BasicDownloadable)
4256
assert d.extension == "flac"
4357
assert isinstance(d.url, str)
@@ -47,8 +61,8 @@ def test_client_get_downloadable(client):
4761
@pytest.mark.skipif(
4862
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
4963
)
50-
def test_client_search_limit(client):
51-
res = client.search("album", "rumours", limit=5)
64+
def test_client_search_limit(qobuz_client):
65+
res = qobuz_client.search("album", "rumours", limit=5)
5266
total = 0
5367
for r in arun(res):
5468
total += len(r["albums"]["items"])
@@ -58,9 +72,9 @@ def test_client_search_limit(client):
5872
@pytest.mark.skipif(
5973
"QOBUZ_EMAIL" not in os.environ, reason="Qobuz credentials not found in env."
6074
)
61-
def test_client_search_no_limit(client):
75+
def test_client_search_no_limit(qobuz_client):
6276
# Setting no limit has become impossible because `limit: int` now
63-
res = client.search("album", "rumours", limit=10000)
77+
res = qobuz_client.search("album", "rumours", limit=10000)
6478
correct_total = 0
6579
total = 0
6680
for r in arun(res):

0 commit comments

Comments
 (0)