mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Prevent tests from speing some ResourceWarnings
This commit is contained in:
parent
5c46c96b53
commit
8e3cd5ef4d
@ -10,6 +10,7 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from contextlib import closing
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pony.orm import db_session
|
from pony.orm import db_session
|
||||||
@ -85,17 +86,19 @@ class MediaTestCase(ApiTestBase):
|
|||||||
"stream", {"id": str(self.trackid), "size": "640x480"}, error=0
|
"stream", {"id": str(self.trackid), "size": "640x480"}, error=0
|
||||||
)
|
)
|
||||||
|
|
||||||
rv = self.client.get(
|
with closing(
|
||||||
"/rest/stream.view",
|
self.client.get(
|
||||||
query_string={
|
"/rest/stream.view",
|
||||||
"u": "alice",
|
query_string={
|
||||||
"p": "Alic3",
|
"u": "alice",
|
||||||
"c": "tests",
|
"p": "Alic3",
|
||||||
"id": str(self.trackid),
|
"c": "tests",
|
||||||
},
|
"id": str(self.trackid),
|
||||||
)
|
},
|
||||||
self.assertEqual(rv.status_code, 200)
|
)
|
||||||
self.assertEqual(len(rv.data), 23)
|
) as rv:
|
||||||
|
self.assertEqual(rv.status_code, 200)
|
||||||
|
self.assertEqual(len(rv.data), 23)
|
||||||
with db_session:
|
with db_session:
|
||||||
self.assertEqual(Track[self.trackid].play_count, 1)
|
self.assertEqual(Track[self.trackid].play_count, 1)
|
||||||
|
|
||||||
@ -105,17 +108,19 @@ class MediaTestCase(ApiTestBase):
|
|||||||
self._make_request("download", {"id": str(uuid.uuid4())}, error=70)
|
self._make_request("download", {"id": str(uuid.uuid4())}, error=70)
|
||||||
|
|
||||||
# download single file
|
# download single file
|
||||||
rv = self.client.get(
|
with closing(
|
||||||
"/rest/download.view",
|
self.client.get(
|
||||||
query_string={
|
"/rest/download.view",
|
||||||
"u": "alice",
|
query_string={
|
||||||
"p": "Alic3",
|
"u": "alice",
|
||||||
"c": "tests",
|
"p": "Alic3",
|
||||||
"id": str(self.trackid),
|
"c": "tests",
|
||||||
},
|
"id": str(self.trackid),
|
||||||
)
|
},
|
||||||
self.assertEqual(rv.status_code, 200)
|
)
|
||||||
self.assertEqual(len(rv.data), 23)
|
) as rv:
|
||||||
|
self.assertEqual(rv.status_code, 200)
|
||||||
|
self.assertEqual(len(rv.data), 23)
|
||||||
with db_session:
|
with db_session:
|
||||||
self.assertEqual(Track[self.trackid].play_count, 0)
|
self.assertEqual(Track[self.trackid].play_count, 0)
|
||||||
|
|
||||||
@ -142,47 +147,57 @@ class MediaTestCase(ApiTestBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
args = {"u": "alice", "p": "Alic3", "c": "tests", "id": str(self.folderid)}
|
args = {"u": "alice", "p": "Alic3", "c": "tests", "id": str(self.folderid)}
|
||||||
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
|
with closing(
|
||||||
self.assertEqual(rv.status_code, 200)
|
self.client.get("/rest/getCoverArt.view", query_string=args)
|
||||||
self.assertEqual(rv.mimetype, "image/jpeg")
|
) as rv:
|
||||||
im = Image.open(BytesIO(rv.data))
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertEqual(im.format, "JPEG")
|
self.assertEqual(rv.mimetype, "image/jpeg")
|
||||||
self.assertEqual(im.size, (420, 420))
|
im = Image.open(BytesIO(rv.data))
|
||||||
|
self.assertEqual(im.format, "JPEG")
|
||||||
|
self.assertEqual(im.size, (420, 420))
|
||||||
|
|
||||||
args["size"] = 600
|
args["size"] = 600
|
||||||
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
|
with closing(
|
||||||
self.assertEqual(rv.status_code, 200)
|
self.client.get("/rest/getCoverArt.view", query_string=args)
|
||||||
self.assertEqual(rv.mimetype, "image/jpeg")
|
) as rv:
|
||||||
im = Image.open(BytesIO(rv.data))
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertEqual(im.format, "JPEG")
|
self.assertEqual(rv.mimetype, "image/jpeg")
|
||||||
self.assertEqual(im.size, (420, 420))
|
im = Image.open(BytesIO(rv.data))
|
||||||
|
self.assertEqual(im.format, "JPEG")
|
||||||
|
self.assertEqual(im.size, (420, 420))
|
||||||
|
|
||||||
args["size"] = 120
|
args["size"] = 120
|
||||||
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
|
with closing(
|
||||||
self.assertEqual(rv.status_code, 200)
|
self.client.get("/rest/getCoverArt.view", query_string=args)
|
||||||
self.assertEqual(rv.mimetype, "image/jpeg")
|
) as rv:
|
||||||
im = Image.open(BytesIO(rv.data))
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertEqual(im.format, "JPEG")
|
self.assertEqual(rv.mimetype, "image/jpeg")
|
||||||
self.assertEqual(im.size, (120, 120))
|
im = Image.open(BytesIO(rv.data))
|
||||||
|
self.assertEqual(im.format, "JPEG")
|
||||||
|
self.assertEqual(im.size, (120, 120))
|
||||||
|
|
||||||
# rerequest, just in case
|
# rerequest, just in case
|
||||||
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
|
with closing(
|
||||||
self.assertEqual(rv.status_code, 200)
|
self.client.get("/rest/getCoverArt.view", query_string=args)
|
||||||
self.assertEqual(rv.mimetype, "image/jpeg")
|
) as rv:
|
||||||
im = Image.open(BytesIO(rv.data))
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertEqual(im.format, "JPEG")
|
self.assertEqual(rv.mimetype, "image/jpeg")
|
||||||
self.assertEqual(im.size, (120, 120))
|
im = Image.open(BytesIO(rv.data))
|
||||||
|
self.assertEqual(im.format, "JPEG")
|
||||||
|
self.assertEqual(im.size, (120, 120))
|
||||||
|
|
||||||
# TODO test non square covers
|
# TODO test non square covers
|
||||||
|
|
||||||
# Test extracting cover art from embeded media
|
# Test extracting cover art from embeded media
|
||||||
for args["id"] in self.formats:
|
for args["id"] in self.formats:
|
||||||
rv = self.client.get("/rest/getCoverArt.view", query_string=args)
|
with closing(
|
||||||
self.assertEqual(rv.status_code, 200)
|
self.client.get("/rest/getCoverArt.view", query_string=args)
|
||||||
self.assertEqual(rv.mimetype, "image/png")
|
) as rv:
|
||||||
im = Image.open(BytesIO(rv.data))
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertEqual(im.format, "PNG")
|
self.assertEqual(rv.mimetype, "image/png")
|
||||||
self.assertEqual(im.size, (120, 120))
|
im = Image.open(BytesIO(rv.data))
|
||||||
|
self.assertEqual(im.format, "PNG")
|
||||||
|
self.assertEqual(im.size, (120, 120))
|
||||||
|
|
||||||
def test_get_avatar(self):
|
def test_get_avatar(self):
|
||||||
self._make_request("getAvatar", error=0)
|
self._make_request("getAvatar", error=0)
|
||||||
|
Loading…
Reference in New Issue
Block a user