1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Prevent tests from speing some ResourceWarnings

This commit is contained in:
Alban Féron 2020-11-08 15:40:37 +01:00
parent 5c46c96b53
commit 8e3cd5ef4d
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165

View File

@ -10,6 +10,7 @@
import os.path
import uuid
from contextlib import closing
from io import BytesIO
from PIL import Image
from pony.orm import db_session
@ -85,7 +86,8 @@ class MediaTestCase(ApiTestBase):
"stream", {"id": str(self.trackid), "size": "640x480"}, error=0
)
rv = self.client.get(
with closing(
self.client.get(
"/rest/stream.view",
query_string={
"u": "alice",
@ -94,6 +96,7 @@ class MediaTestCase(ApiTestBase):
"id": str(self.trackid),
},
)
) as rv:
self.assertEqual(rv.status_code, 200)
self.assertEqual(len(rv.data), 23)
with db_session:
@ -105,7 +108,8 @@ class MediaTestCase(ApiTestBase):
self._make_request("download", {"id": str(uuid.uuid4())}, error=70)
# download single file
rv = self.client.get(
with closing(
self.client.get(
"/rest/download.view",
query_string={
"u": "alice",
@ -114,6 +118,7 @@ class MediaTestCase(ApiTestBase):
"id": str(self.trackid),
},
)
) as rv:
self.assertEqual(rv.status_code, 200)
self.assertEqual(len(rv.data), 23)
with db_session:
@ -142,7 +147,9 @@ class MediaTestCase(ApiTestBase):
)
args = {"u": "alice", "p": "Alic3", "c": "tests", "id": str(self.folderid)}
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
with closing(
self.client.get("/rest/getCoverArt.view", query_string=args)
) as rv:
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.mimetype, "image/jpeg")
im = Image.open(BytesIO(rv.data))
@ -150,7 +157,9 @@ class MediaTestCase(ApiTestBase):
self.assertEqual(im.size, (420, 420))
args["size"] = 600
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
with closing(
self.client.get("/rest/getCoverArt.view", query_string=args)
) as rv:
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.mimetype, "image/jpeg")
im = Image.open(BytesIO(rv.data))
@ -158,7 +167,9 @@ class MediaTestCase(ApiTestBase):
self.assertEqual(im.size, (420, 420))
args["size"] = 120
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
with closing(
self.client.get("/rest/getCoverArt.view", query_string=args)
) as rv:
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.mimetype, "image/jpeg")
im = Image.open(BytesIO(rv.data))
@ -166,7 +177,9 @@ class MediaTestCase(ApiTestBase):
self.assertEqual(im.size, (120, 120))
# rerequest, just in case
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
with closing(
self.client.get("/rest/getCoverArt.view", query_string=args)
) as rv:
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.mimetype, "image/jpeg")
im = Image.open(BytesIO(rv.data))
@ -177,7 +190,9 @@ class MediaTestCase(ApiTestBase):
# Test extracting cover art from embeded media
for args["id"] in self.formats:
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
with closing(
self.client.get("/rest/getCoverArt.view", query_string=args)
) as rv:
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.mimetype, "image/png")
im = Image.open(BytesIO(rv.data))