Skip to content

Commit

Permalink
Merge pull request #94 from joalla/fix_search_type_err
Browse files Browse the repository at this point in the history
Fix bytes concatination error in Client.search()
  • Loading branch information
JOJ0 authored May 19, 2022
2 parents 65e8e95 + 037dd3f commit 6209dc3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion discogs_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ def search(self, *query, **fields):
function are serialized into the request's query string.
"""
if query:
fields['q'] = ' '.join(query)
items = [
item.decode() if type(item) == bytes else item for item in query
]
fields['q'] = ' '.join(items)

return models.MixedPaginatedList(
self,
update_qs(self._base_url + '/database/search', fields),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pagination": {"per_page": 50, "pages": 1, "page": 1, "urls": {}, "items": 13}, "results": [{"thumb": null, "title": "Trash80", "uri": "/artist/Trash80", "resource_url": "/artists/95780", "type": "artist", "id": 95780}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1743771-1272253277.gif", "title": "Trash80 - Icarus", "country": "US", "format": ["CDr"], "uri": "/Trash80-Icarus/release/1743771", "label": "8bitpeoples", "catno": "8BP086", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1743771", "type": "release", "id": 1743771}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1346442-1211545307.gif", "title": "Trash80 - Icarus", "country": "US", "format": ["File"], "uri": "/Trash80-Icarus/release/1346442", "label": "8bitpeoples", "catno": "8BP086", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1346442", "type": "release", "id": 1346442}, {"style": ["Chiptune"], "thumb": "/image/R-90-480740-1149028432.gif", "title": "Trash80 - Hologram", "country": "US", "format": ["File"], "uri": "/Trash80-Hologram/release/480740", "label": "8bitpeoples", "catno": "8BP037", "year": "2003", "genre": ["Electronic"], "resource_url": "/releases/480740", "type": "release", "id": 480740}, {"style": ["Modern Classical", "Chiptune", "Breaks", "Ambient"], "thumb": "/image/R-90-3329867-1326034108.jpeg", "title": "Trash80 & Dma-Sc - Darwinia Soundtrack", "country": "UK", "format": ["File"], "uri": "/Trash80-Dma-Sc-Darwinia-Soundtrack/release/3329867", "label": "Not On Label", "catno": "none", "year": "2005", "genre": ["Electronic"], "resource_url": "/releases/3329867", "type": "release", "id": 3329867}, {"style": ["Chiptune"], "thumb": "/image/R-90-1554401-1227991910.gif", "title": "Nullsleep - Unconditional Acceleration", "country": "US", "format": ["File"], "uri": "/Nullsleep-Unconditional-Acceleration/release/1554401", "label": "8bitpeoples", "catno": "8BP088", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1554401", "type": "release", "id": 1554401}, {"style": ["Chiptune"], "thumb": "/image/R-90-2634760-1294296299.gif", "title": "Sievert - Chips, Dips And Facerips", "country": "US", "format": ["File"], "uri": "/Sievert-Chips-Dips-And-Facerips/release/2634760", "label": "8bitpeoples", "catno": "8BP113", "year": "2011", "genre": ["Electronic"], "resource_url": "/releases/2634760", "type": "release", "id": 2634760}, {"style": ["Chiptune"], "thumb": "/image/R-90-1554411-1228435569.jpeg", "title": "Minusbaby - Saudade For Beginners", "country": "US", "format": ["File", "CD"], "uri": "/Minusbaby-Saudade-For-Beginners/release/1554411", "label": "8bitpeoples", "catno": "8BP089", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1554411", "type": "release", "id": 1554411}, {"style": ["Abstract", "Musique Concr\u00e8te", "Experimental"], "thumb": null, "title": "Larry Wendt - Sound Poems For An Era Of Reduced Expectations", "country": "US", "format": ["Cassette"], "uri": "/Larry-Wendt-Sound-Poems-For-An-Era-Of-Reduced-Expectations/release/2674683", "label": "Underwhich Audiographics", "catno": "5", "genre": ["Electronic", "Non-Music"], "resource_url": "/releases/2674683", "type": "release", "id": 2674683}, {"style": ["Breakbeat", "Interview", "Techno", "IDM", "Minimal"], "thumb": null, "title": "Datamat - Interjamp Realaudio Special", "country": "Germany", "format": ["File"], "uri": "/Datamat-Interjamp-Realaudio-Special/release/1994383", "label": "Interjamp Radio", "catno": "inter004", "year": "2004", "genre": ["Electronic", "Non-Music"], "resource_url": "/releases/1994383", "type": "release", "id": 1994383}, {"style": ["IDM", "Noise", "Experimental"], "thumb": "/image/R-90-132406-1177641432.jpeg", "title": "Various - One Minute Massacre Volume 1", "country": "", "format": ["CD"], "uri": "/Various-One-Minute-Massacre-Volume-1/release/132406", "label": "Soulseek Records", "catno": "SLSK002", "year": "2003", "genre": ["Electronic"], "resource_url": "/releases/132406", "type": "release", "id": 132406}, {"style": ["Chiptune", "Experimental"], "thumb": "/image/R-90-915735-1229262615.jpeg", "title": "Various - 8BP050", "country": "US", "format": ["CD", "File"], "uri": "/Various-8BP050/release/915735", "label": "8bitpeoples", "catno": "8BP050", "year": "2006", "genre": ["Electronic"], "resource_url": "/releases/915735", "type": "release", "id": 915735}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1903567-1251600832.jpeg", "title": "Various - Blip Festival 2008: 32 Live Recordings", "country": "US", "format": ["CD"], "uri": "/Various-Blip-Festival-2008-32-Live-Recordings/release/1903567", "label": "8bitpeoples", "catno": "8BP100", "year": "2009", "genre": ["Electronic"], "resource_url": "/releases/1903567", "type": "release", "id": 1903567}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pagination": {"per_page": 50, "pages": 1, "page": 1, "urls": {}, "items": 13}, "results": [{"thumb": null, "title": "Trash80", "uri": "/artist/Trash80", "resource_url": "/artists/95780", "type": "artist", "id": 95780}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1743771-1272253277.gif", "title": "Trash80 - Icarus", "country": "US", "format": ["CDr"], "uri": "/Trash80-Icarus/release/1743771", "label": "8bitpeoples", "catno": "8BP086", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1743771", "type": "release", "id": 1743771}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1346442-1211545307.gif", "title": "Trash80 - Icarus", "country": "US", "format": ["File"], "uri": "/Trash80-Icarus/release/1346442", "label": "8bitpeoples", "catno": "8BP086", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1346442", "type": "release", "id": 1346442}, {"style": ["Chiptune"], "thumb": "/image/R-90-480740-1149028432.gif", "title": "Trash80 - Hologram", "country": "US", "format": ["File"], "uri": "/Trash80-Hologram/release/480740", "label": "8bitpeoples", "catno": "8BP037", "year": "2003", "genre": ["Electronic"], "resource_url": "/releases/480740", "type": "release", "id": 480740}, {"style": ["Modern Classical", "Chiptune", "Breaks", "Ambient"], "thumb": "/image/R-90-3329867-1326034108.jpeg", "title": "Trash80 & Dma-Sc - Darwinia Soundtrack", "country": "UK", "format": ["File"], "uri": "/Trash80-Dma-Sc-Darwinia-Soundtrack/release/3329867", "label": "Not On Label", "catno": "none", "year": "2005", "genre": ["Electronic"], "resource_url": "/releases/3329867", "type": "release", "id": 3329867}, {"style": ["Chiptune"], "thumb": "/image/R-90-1554401-1227991910.gif", "title": "Nullsleep - Unconditional Acceleration", "country": "US", "format": ["File"], "uri": "/Nullsleep-Unconditional-Acceleration/release/1554401", "label": "8bitpeoples", "catno": "8BP088", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1554401", "type": "release", "id": 1554401}, {"style": ["Chiptune"], "thumb": "/image/R-90-2634760-1294296299.gif", "title": "Sievert - Chips, Dips And Facerips", "country": "US", "format": ["File"], "uri": "/Sievert-Chips-Dips-And-Facerips/release/2634760", "label": "8bitpeoples", "catno": "8BP113", "year": "2011", "genre": ["Electronic"], "resource_url": "/releases/2634760", "type": "release", "id": 2634760}, {"style": ["Chiptune"], "thumb": "/image/R-90-1554411-1228435569.jpeg", "title": "Minusbaby - Saudade For Beginners", "country": "US", "format": ["File", "CD"], "uri": "/Minusbaby-Saudade-For-Beginners/release/1554411", "label": "8bitpeoples", "catno": "8BP089", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1554411", "type": "release", "id": 1554411}, {"style": ["Abstract", "Musique Concr\u00e8te", "Experimental"], "thumb": null, "title": "Larry Wendt - Sound Poems For An Era Of Reduced Expectations", "country": "US", "format": ["Cassette"], "uri": "/Larry-Wendt-Sound-Poems-For-An-Era-Of-Reduced-Expectations/release/2674683", "label": "Underwhich Audiographics", "catno": "5", "genre": ["Electronic", "Non-Music"], "resource_url": "/releases/2674683", "type": "release", "id": 2674683}, {"style": ["Breakbeat", "Interview", "Techno", "IDM", "Minimal"], "thumb": null, "title": "Datamat - Interjamp Realaudio Special", "country": "Germany", "format": ["File"], "uri": "/Datamat-Interjamp-Realaudio-Special/release/1994383", "label": "Interjamp Radio", "catno": "inter004", "year": "2004", "genre": ["Electronic", "Non-Music"], "resource_url": "/releases/1994383", "type": "release", "id": 1994383}, {"style": ["IDM", "Noise", "Experimental"], "thumb": "/image/R-90-132406-1177641432.jpeg", "title": "Various - One Minute Massacre Volume 1", "country": "", "format": ["CD"], "uri": "/Various-One-Minute-Massacre-Volume-1/release/132406", "label": "Soulseek Records", "catno": "SLSK002", "year": "2003", "genre": ["Electronic"], "resource_url": "/releases/132406", "type": "release", "id": 132406}, {"style": ["Chiptune", "Experimental"], "thumb": "/image/R-90-915735-1229262615.jpeg", "title": "Various - 8BP050", "country": "US", "format": ["CD", "File"], "uri": "/Various-8BP050/release/915735", "label": "8bitpeoples", "catno": "8BP050", "year": "2006", "genre": ["Electronic"], "resource_url": "/releases/915735", "type": "release", "id": 915735}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1903567-1251600832.jpeg", "title": "Various - Blip Festival 2008: 32 Live Recordings", "country": "US", "format": ["CD"], "uri": "/Various-Blip-Festival-2008-32-Live-Recordings/release/1903567", "label": "8bitpeoples", "catno": "8BP100", "year": "2009", "genre": ["Electronic"], "resource_url": "/releases/1903567", "type": "release", "id": 1903567}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pagination": {"per_page": 50, "pages": 1, "page": 1, "urls": {}, "items": 13}, "results": [{"thumb": null, "title": "Trash80", "uri": "/artist/Trash80", "resource_url": "/artists/95780", "type": "artist", "id": 95780}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1743771-1272253277.gif", "title": "Trash80 - Icarus", "country": "US", "format": ["CDr"], "uri": "/Trash80-Icarus/release/1743771", "label": "8bitpeoples", "catno": "8BP086", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1743771", "type": "release", "id": 1743771}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1346442-1211545307.gif", "title": "Trash80 - Icarus", "country": "US", "format": ["File"], "uri": "/Trash80-Icarus/release/1346442", "label": "8bitpeoples", "catno": "8BP086", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1346442", "type": "release", "id": 1346442}, {"style": ["Chiptune"], "thumb": "/image/R-90-480740-1149028432.gif", "title": "Trash80 - Hologram", "country": "US", "format": ["File"], "uri": "/Trash80-Hologram/release/480740", "label": "8bitpeoples", "catno": "8BP037", "year": "2003", "genre": ["Electronic"], "resource_url": "/releases/480740", "type": "release", "id": 480740}, {"style": ["Modern Classical", "Chiptune", "Breaks", "Ambient"], "thumb": "/image/R-90-3329867-1326034108.jpeg", "title": "Trash80 & Dma-Sc - Darwinia Soundtrack", "country": "UK", "format": ["File"], "uri": "/Trash80-Dma-Sc-Darwinia-Soundtrack/release/3329867", "label": "Not On Label", "catno": "none", "year": "2005", "genre": ["Electronic"], "resource_url": "/releases/3329867", "type": "release", "id": 3329867}, {"style": ["Chiptune"], "thumb": "/image/R-90-1554401-1227991910.gif", "title": "Nullsleep - Unconditional Acceleration", "country": "US", "format": ["File"], "uri": "/Nullsleep-Unconditional-Acceleration/release/1554401", "label": "8bitpeoples", "catno": "8BP088", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1554401", "type": "release", "id": 1554401}, {"style": ["Chiptune"], "thumb": "/image/R-90-2634760-1294296299.gif", "title": "Sievert - Chips, Dips And Facerips", "country": "US", "format": ["File"], "uri": "/Sievert-Chips-Dips-And-Facerips/release/2634760", "label": "8bitpeoples", "catno": "8BP113", "year": "2011", "genre": ["Electronic"], "resource_url": "/releases/2634760", "type": "release", "id": 2634760}, {"style": ["Chiptune"], "thumb": "/image/R-90-1554411-1228435569.jpeg", "title": "Minusbaby - Saudade For Beginners", "country": "US", "format": ["File", "CD"], "uri": "/Minusbaby-Saudade-For-Beginners/release/1554411", "label": "8bitpeoples", "catno": "8BP089", "year": "2008", "genre": ["Electronic"], "resource_url": "/releases/1554411", "type": "release", "id": 1554411}, {"style": ["Abstract", "Musique Concr\u00e8te", "Experimental"], "thumb": null, "title": "Larry Wendt - Sound Poems For An Era Of Reduced Expectations", "country": "US", "format": ["Cassette"], "uri": "/Larry-Wendt-Sound-Poems-For-An-Era-Of-Reduced-Expectations/release/2674683", "label": "Underwhich Audiographics", "catno": "5", "genre": ["Electronic", "Non-Music"], "resource_url": "/releases/2674683", "type": "release", "id": 2674683}, {"style": ["Breakbeat", "Interview", "Techno", "IDM", "Minimal"], "thumb": null, "title": "Datamat - Interjamp Realaudio Special", "country": "Germany", "format": ["File"], "uri": "/Datamat-Interjamp-Realaudio-Special/release/1994383", "label": "Interjamp Radio", "catno": "inter004", "year": "2004", "genre": ["Electronic", "Non-Music"], "resource_url": "/releases/1994383", "type": "release", "id": 1994383}, {"style": ["IDM", "Noise", "Experimental"], "thumb": "/image/R-90-132406-1177641432.jpeg", "title": "Various - One Minute Massacre Volume 1", "country": "", "format": ["CD"], "uri": "/Various-One-Minute-Massacre-Volume-1/release/132406", "label": "Soulseek Records", "catno": "SLSK002", "year": "2003", "genre": ["Electronic"], "resource_url": "/releases/132406", "type": "release", "id": 132406}, {"style": ["Chiptune", "Experimental"], "thumb": "/image/R-90-915735-1229262615.jpeg", "title": "Various - 8BP050", "country": "US", "format": ["CD", "File"], "uri": "/Various-8BP050/release/915735", "label": "8bitpeoples", "catno": "8BP050", "year": "2006", "genre": ["Electronic"], "resource_url": "/releases/915735", "type": "release", "id": 915735}, {"style": ["Electro", "Chiptune"], "thumb": "/image/R-90-1903567-1251600832.jpeg", "title": "Various - Blip Festival 2008: 32 Live Recordings", "country": "US", "format": ["CD"], "uri": "/Various-Blip-Festival-2008-32-Live-Recordings/release/1903567", "label": "8bitpeoples", "catno": "8BP100", "year": "2009", "genre": ["Electronic"], "resource_url": "/releases/1903567", "type": "release", "id": 1903567}]}
36 changes: 36 additions & 0 deletions discogs_client/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ def test_search(self):
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_bytes_search(self):
results = self.d.search(b'trash80')
self.assertEqual(len(results), 13)
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_multiterm_search(self):
results = self.d.search('trash', '80')
self.assertEqual(len(results), 13)
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_multiterm_bytes_search(self):
results = self.d.search(b'trash', b'80')
self.assertEqual(len(results), 13)
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_multiterm_mixed_search(self):
results = self.d.search('trash', b'80')
self.assertEqual(len(results), 13)
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_kwargs_search(self):
results = self.d.search(artist='trash80')
self.assertEqual(len(results), 13)
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_kwargs_multiterm_search(self):
results = self.d.search(title='icarus', artist='trash80')
self.assertEqual(len(results), 13)
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_utf8_search(self):
uni_string = 'caf\xe9'
try:
Expand Down

0 comments on commit 6209dc3

Please sign in to comment.