From d05f69dd269ca02404f4c945d228cb59464439a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alban=20F=C3=A9ron?= Date: Sat, 13 Jul 2019 16:33:22 +0200 Subject: [PATCH] Move lyrics test out of the main test suite Ref #130 --- .travis.yml | 4 ++- tests/api/test_lyrics.py | 68 ++++++++++++++++++++++++++++++++++++++++ tests/api/test_media.py | 50 ----------------------------- 3 files changed, 71 insertions(+), 51 deletions(-) create mode 100644 tests/api/test_lyrics.py diff --git a/.travis.yml b/.travis.yml index 85cae3a..2e10b8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,7 @@ python: - 3.7 install: - 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 diff --git a/tests/api/test_lyrics.py b/tests/api/test_lyrics.py new file mode 100644 index 0000000..bed1df2 --- /dev/null +++ b/tests/api/test_lyrics.py @@ -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() diff --git a/tests/api/test_media.py b/tests/api/test_media.py index 397fca0..42c14e3 100644 --- a/tests/api/test_media.py +++ b/tests/api/test_media.py @@ -8,9 +8,7 @@ # # Distributed under terms of the GNU AGPLv3 license. -import flask.json import os.path -import requests import uuid from io import BytesIO @@ -186,54 +184,6 @@ class MediaTestCase(ApiTestBase): self.assertEqual(im.format, "PNG") 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): self._make_request("getAvatar", error=0)