Fixed error caused by unrecognized favorite not yielding result in search

This commit is contained in:
Eric van Blokland
2021-09-28 16:18:29 +02:00
parent 0df2ad24b7
commit 34e4892975
2 changed files with 17 additions and 5 deletions

View File

@@ -370,10 +370,15 @@ class RadioNetClient(object):
logger.debug("Radio.net: Done search") logger.debug("Radio.net: Done search")
json = response.json() json = response.json()
number_pages = int(json["numberPages"])
logger.error(json)
if number_pages != 0:
# take only the first match! # take only the first match!
station = self._get_station_from_search_result( station = self._get_station_from_search_result(
json["categories"][0]["matches"][0] json["categories"][0]["matches"][0]
) )
else:
logger.warning("Radio.net: No results for %s", station_slug)
if station and station.playable: if station and station.playable:
favorite_stations.append(station) favorite_stations.append(station)

View File

@@ -26,9 +26,16 @@ def test_do_search(radionet):
def test_get_favorites(radionet): def test_get_favorites(radionet):
test_favorites = ("Rock Antenne", "radio ram", "eska", "dancefm") test_favorites = ["Rock Antenne", "radio ram", "eska", "dancefm"]
radionet.set_favorites(test_favorites) radionet.set_favorites(test_favorites)
result = radionet.get_favorites() result = radionet.get_favorites()
assert len(result) == len(test_favorites) assert len(result) == len(test_favorites)
assert result[2].name == 'Eska' assert result[2].name == 'Eska'
def test_favorites_broken_slug(radionet):
test_favorites = ["radio357"]
radionet.set_favorites(test_favorites)
result = radionet.get_favorites()
assert len(result) == 0