mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
Remove the ability to skip XSD validation in tests
We have int folder ids for long now, this isn't needed anymore
This commit is contained in:
parent
1be526b8d2
commit
e0946c0e32
@ -1,9 +1,7 @@
|
||||
# coding: utf-8
|
||||
#
|
||||
# This file is part of Supysonic.
|
||||
# Supysonic is a Python implementation of the Subsonic server API.
|
||||
#
|
||||
# Copyright (C) 2017-2018 Alban 'spl0k' Féron
|
||||
# Copyright (C) 2017-2020 Alban 'spl0k' Féron
|
||||
#
|
||||
# Distributed under terms of the GNU AGPLv3 license.
|
||||
|
||||
@ -45,9 +43,7 @@ class ApiTestBase(TestBase):
|
||||
path = path_replace_regexp.sub(r"/sub:\1", path)
|
||||
return elem.xpath(path, namespaces=NSMAP)
|
||||
|
||||
def _make_request(
|
||||
self, endpoint, args={}, tag=None, error=None, skip_post=False, skip_xsd=False
|
||||
):
|
||||
def _make_request(self, endpoint, args={}, tag=None, error=None, skip_post=False):
|
||||
"""
|
||||
Makes both a GET and POST requests against the API, assert both get the same response.
|
||||
If the user isn't provided with the 'u' and 'p' in 'args', the default 'alice' is used.
|
||||
@ -58,7 +54,6 @@ class ApiTestBase(TestBase):
|
||||
:param tag: topmost expected element, right beneath 'subsonic-response'
|
||||
:param error: if the given 'args' should produce an error at 'endpoint', this is the expected error code
|
||||
:param skip_post: don't do the POST request
|
||||
:param skip_xsd: skip XSD validation
|
||||
|
||||
:return: a 2-tuple (resp, child) if no error, where 'resp' is the full response object, 'child' a
|
||||
'lxml.etree.Element' mathching 'tag' (if any). If there's an error (when expected), only returns
|
||||
@ -81,8 +76,7 @@ class ApiTestBase(TestBase):
|
||||
self.assertEqual(rg.data, rp.data)
|
||||
|
||||
xml = etree.fromstring(rg.data)
|
||||
if not skip_xsd:
|
||||
self.schema.assert_(xml)
|
||||
self.schema.assert_(xml)
|
||||
|
||||
if xml.get("status") == "ok":
|
||||
self.assertIsNone(error)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
#
|
||||
# This file is part of Supysonic.
|
||||
# Supysonic is a Python implementation of the Subsonic server API.
|
||||
@ -53,15 +52,15 @@ class AnnotationTestCase(ApiTestBase):
|
||||
|
||||
def test_star(self):
|
||||
self._make_request("star", error=10)
|
||||
self._make_request("star", {"id": "unknown"}, error=0, skip_xsd=True)
|
||||
self._make_request("star", {"id": "unknown"}, error=0)
|
||||
self._make_request("star", {"albumId": "unknown"}, error=0)
|
||||
self._make_request("star", {"artistId": "unknown"}, error=0)
|
||||
self._make_request("star", {"id": str(uuid.uuid4())}, error=70, skip_xsd=True)
|
||||
self._make_request("star", {"id": str(uuid.uuid4())}, error=70)
|
||||
self._make_request("star", {"albumId": str(uuid.uuid4())}, error=70)
|
||||
self._make_request("star", {"artistId": str(uuid.uuid4())}, error=70)
|
||||
|
||||
self._make_request("star", {"id": str(self.artistid)}, error=70, skip_xsd=True)
|
||||
self._make_request("star", {"id": str(self.albumid)}, error=70, skip_xsd=True)
|
||||
self._make_request("star", {"id": str(self.artistid)}, error=70)
|
||||
self._make_request("star", {"id": str(self.albumid)}, error=70)
|
||||
self._make_request("star", {"id": str(self.trackid)}, skip_post=True)
|
||||
with db_session:
|
||||
prefs = ClientPrefs.get(
|
||||
@ -70,12 +69,12 @@ class AnnotationTestCase(ApiTestBase):
|
||||
self.assertIn(
|
||||
"starred", Track[self.trackid].as_subsonic_child(self.user, prefs)
|
||||
)
|
||||
self._make_request("star", {"id": str(self.trackid)}, error=0, skip_xsd=True)
|
||||
self._make_request("star", {"id": str(self.trackid)}, error=0)
|
||||
|
||||
self._make_request("star", {"id": str(self.folderid)}, skip_post=True)
|
||||
with db_session:
|
||||
self.assertIn("starred", Folder[self.folderid].as_subsonic_child(self.user))
|
||||
self._make_request("star", {"id": str(self.folderid)}, error=0, skip_xsd=True)
|
||||
self._make_request("star", {"id": str(self.folderid)}, error=0)
|
||||
|
||||
self._make_request("star", {"albumId": str(self.folderid)}, error=0)
|
||||
self._make_request("star", {"albumId": str(self.artistid)}, error=70)
|
||||
@ -107,7 +106,7 @@ class AnnotationTestCase(ApiTestBase):
|
||||
)
|
||||
|
||||
self._make_request("unstar", error=10)
|
||||
self._make_request("unstar", {"id": "unknown"}, error=0, skip_xsd=True)
|
||||
self._make_request("unstar", {"id": "unknown"}, error=0)
|
||||
self._make_request("unstar", {"albumId": "unknown"}, error=0)
|
||||
self._make_request("unstar", {"artistId": "unknown"}, error=0)
|
||||
|
||||
|
@ -69,11 +69,7 @@ class BrowseTestCase(ApiTestBase):
|
||||
self.assertEqual(Track.select().count(), 18)
|
||||
|
||||
def test_get_music_folders(self):
|
||||
# Do not validate against the XSD here, this is the only place where the API should return ids as ints
|
||||
# all our ids are uuids :/
|
||||
rv, child = self._make_request(
|
||||
"getMusicFolders", tag="musicFolders", skip_xsd=True
|
||||
)
|
||||
rv, child = self._make_request("getMusicFolders", tag="musicFolders")
|
||||
self.assertEqual(len(child), 2)
|
||||
self.assertSequenceEqual(
|
||||
sorted(self._xpath(child, "./musicFolder/@name")),
|
||||
|
Loading…
Reference in New Issue
Block a user