mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-10-11 17:10:45 +00:00
Warn when a search query exceeds Spotify's length limit
This commit is contained in:
3 files changed
+50
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
|
||||
from spotipy import Spotify
|
||||
|
||||
|
||||
class SearchQueryLengthTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.spotify = Spotify(auth="TOKEN")
|
||||
|
||||
@mock.patch.object(Spotify, "_internal_call", return_value={})
|
||||
def test_long_query_warns(self, _internal_call):
|
||||
query = "a" * (Spotify.max_search_query_length + 1)
|
||||
with self.assertLogs("spotipy.client", level="WARNING") as logs:
|
||||
self.spotify.search(query)
|
||||
self.assertTrue(
|
||||
any("character limit" in message or "character" in message
|
||||
for message in logs.output)
|
||||
)
|
||||
|
||||
@mock.patch.object(Spotify, "_internal_call", return_value={})
|
||||
def test_short_query_does_not_warn(self, _internal_call):
|
||||
query = "a" * Spotify.max_search_query_length
|
||||
logger = "spotipy.client"
|
||||
with self.assertRaises(AssertionError):
|
||||
with self.assertLogs(logger, level="WARNING"):
|
||||
self.spotify.search(query)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user