Skip to content

Commit

Permalink
Merge pull request #67 from andreztz/remove-code
Browse files Browse the repository at this point in the history
Remove code that replaced the filter of the API.
  • Loading branch information
andreztz authored Oct 22, 2023
2 parents e5a6bfc + e5887d7 commit 67fb731
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 46 deletions.
50 changes: 11 additions & 39 deletions pyradios/radios.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,12 @@ def codecs(self, codec=None):
See details:
https://de1.api.radio-browser.info/#List_of_codecs
"""
if codec:
endpoint = "json/codecs/{}".format(codec)
else:
endpoint = "json/codecs/"

endpoint = "json/codecs/"
url = self.build_url(endpoint)

if codec:
response = self.client.get(url)
return list(
filter(
lambda _codecs: _codecs["name"].lower() == codec.lower(),
response,
)
)
return self.client.get(url)

@type_check
Expand All @@ -156,38 +150,16 @@ def states(self, country=None, state=None):
https://de1.api.radio-browser.info/#List_of_states
"""

endpoint = "json/states"

url = self.build_url(endpoint)
endpoint = "json/states/"

if country and state:
endpoint += "{}/{}".format(country.title(), state.title())
elif country:
endpoint += "{}".format(country.title())
elif state:
endpoint += "{}".format(state.title())

response = self.client.get(url)
return list(
filter(
lambda _state: _state["country"].lower() == country.lower()
and _state["name"].lower() == state.lower(),
response,
)
)

if country:
response = self.client.get(url)
return list(
filter(
lambda _state: _state["country"].lower()
== country.lower(),
response,
)
)
if state:
response = self.client.get(url)
return list(
filter(
lambda _state: _state["name"].lower() == state.lower(),
response,
)
)
url = self.build_url(endpoint)
return self.client.get(url)

@type_check
Expand Down
13 changes: 6 additions & 7 deletions tests/test_radio_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_request_codecs(rb):
assert "stationcount" in resp[0]


@responses.activate
# @responses.activate
def test_request_codecs_with_filters(rb):
"""
This test runs against a subset of the API response, with the sole
Expand All @@ -170,21 +170,20 @@ def test_request_codecs_with_filters(rb):
]
responses.add(
responses.GET,
BASE_URL + "json/codecs/",
BASE_URL + "json/codecs/mp3",
json=payload,
status=200,
)

resp = rb.codecs(codec="mp3")
assert len(resp) == 1
assert len(resp) == 2
assert resp[0]["name"] == "MP3", "only one codec should be in the response"


def test_request_states_with_filters(rb):

# expected = [{"name": "Parana", "country": "Brazil", "stationcount": 23}]

resp = rb.states(country="BRAZIL", state="Parana")
# Note: `country` and `state` should be provided in "titlecased",
# like so: `str().title()`
resp = rb.states(country="Brazil", state="Paraná")

assert len(resp) > 0, "at least one state should be in the response"
assert "name" in resp[0]
Expand Down

0 comments on commit 67fb731

Please sign in to comment.