1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Move lyrics test out of the main test suite

Ref #130
This commit is contained in:
Alban Féron 2019-07-13 16:33:22 +02:00
parent ce792e39c5
commit d05f69dd26
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
3 changed files with 71 additions and 51 deletions

View File

@ -7,5 +7,7 @@ python:
- 3.7 - 3.7
install: install:
- pip install -r travis-requirements.txt - pip install -r travis-requirements.txt
script: coverage run setup.py test script:
- coverage run setup.py test
- coverage run setup.py test --test-suite tests.api.test_lyrics
after_script: codecov after_script: codecov

68
tests/api/test_lyrics.py Normal file
View File

@ -0,0 +1,68 @@
#!/usr/bin/env python
# coding: utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2017 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
import flask.json
import requests
from .apitestbase import ApiTestBase
class LyricsTestCase(ApiTestBase):
def test_get_lyrics(self):
self._make_request("getLyrics", error=10)
self._make_request("getLyrics", {"artist": "artist"}, error=10)
self._make_request("getLyrics", {"title": "title"}, error=10)
# Potentially skip the tests if ChartLyrics is down (which happens quite often)
try:
requests.get("http://api.chartlyrics.com/", timeout=5)
except requests.exceptions.Timeout:
self.skipTest("ChartLyrics down")
rv, child = self._make_request(
"getLyrics",
{
"artist": "some really long name hoping",
"title": "to get absolutely no result",
},
tag="lyrics",
)
self.assertIsNone(child.text)
# ChartLyrics
rv, child = self._make_request(
"getLyrics",
{"artist": "The Clash", "title": "London Calling"},
tag="lyrics",
)
self.assertIn("live by the river", child.text)
# ChartLyrics, JSON format
args = {
"u": "alice",
"p": "Alic3",
"c": "tests",
"f": "json",
"artist": "The Clash",
"title": "London Calling",
}
rv = self.client.get("/rest/getLyrics.view", query_string=args)
json = flask.json.loads(rv.data)
self.assertIn("value", json["subsonic-response"]["lyrics"])
self.assertIn("live by the river", json["subsonic-response"]["lyrics"]["value"])
# Local file
rv, child = self._make_request(
"getLyrics", {"artist": "artist", "title": "23bytes"}, tag="lyrics"
)
self.assertIn("null", child.text)
if __name__ == "__main__":
unittest.main()

View File

@ -8,9 +8,7 @@
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import flask.json
import os.path import os.path
import requests
import uuid import uuid
from io import BytesIO from io import BytesIO
@ -186,54 +184,6 @@ class MediaTestCase(ApiTestBase):
self.assertEqual(im.format, "PNG") self.assertEqual(im.format, "PNG")
self.assertEqual(im.size, (120, 120)) self.assertEqual(im.size, (120, 120))
def test_get_lyrics(self):
self._make_request("getLyrics", error=10)
self._make_request("getLyrics", {"artist": "artist"}, error=10)
self._make_request("getLyrics", {"title": "title"}, error=10)
# Potentially skip the tests if ChartLyrics is down (which happens quite often)
try:
requests.get("http://api.chartlyrics.com/", timeout=5)
except requests.exceptions.Timeout:
self.skipTest("ChartLyrics down")
rv, child = self._make_request(
"getLyrics",
{
"artist": "some really long name hoping",
"title": "to get absolutely no result",
},
tag="lyrics",
)
self.assertIsNone(child.text)
# ChartLyrics
rv, child = self._make_request(
"getLyrics",
{"artist": "The Clash", "title": "London Calling"},
tag="lyrics",
)
self.assertIn("live by the river", child.text)
# ChartLyrics, JSON format
args = {
"u": "alice",
"p": "Alic3",
"c": "tests",
"f": "json",
"artist": "The Clash",
"title": "London Calling",
}
rv = self.client.get("/rest/getLyrics.view", query_string=args)
json = flask.json.loads(rv.data)
self.assertIn("value", json["subsonic-response"]["lyrics"])
self.assertIn("live by the river", json["subsonic-response"]["lyrics"]["value"])
# Local file
rv, child = self._make_request(
"getLyrics", {"artist": "artist", "title": "23bytes"}, tag="lyrics"
)
self.assertIn("null", child.text)
def test_get_avatar(self): def test_get_avatar(self):
self._make_request("getAvatar", error=0) self._make_request("getAvatar", error=0)