diff --git a/requirements-dev.txt b/requirements-dev.txt index daef2ba..1f3c6eb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,3 +3,4 @@ pytest>=6.2.5 flake8>=4.0.1 responses>=0.15.0 setuptools +pytest-recording diff --git a/tests/cassettes/test_radio_browser/test_request_codecs.yaml b/tests/cassettes/test_radio_browser/test_request_codecs.yaml new file mode 100644 index 0000000..fc6f15d --- /dev/null +++ b/tests/cassettes/test_radio_browser/test_request_codecs.yaml @@ -0,0 +1,38 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - pyradios/2.0.0 + method: GET + uri: https://nl1.api.radio-browser.info/json/codecs/ + response: + body: + string: '[{"name":"AAC","stationcount":4449},{"name":"AAC+","stationcount":7495},{"name":"AAC+,H.264","stationcount":4},{"name":"AAC,H.264","stationcount":80},{"name":"FLV","stationcount":10},{"name":"MP3","stationcount":27967},{"name":"MP3,H.264","stationcount":14},{"name":"OGG","stationcount":443},{"name":"UNKNOWN","stationcount":1652}]' + headers: + Access-Control-Allow-Headers: + - origin, x-requested-with, content-type, User-Agent + Access-Control-Allow-Methods: + - GET,POST + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '331' + Content-Type: + - application/json + Date: + - Wed, 25 Oct 2023 06:13:07 GMT + Server: + - nginx/1.18.0 (Ubuntu) + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_radio_browser/test_request_codecs_with_filters.yaml b/tests/cassettes/test_radio_browser/test_request_codecs_with_filters.yaml new file mode 100644 index 0000000..56f3c49 --- /dev/null +++ b/tests/cassettes/test_radio_browser/test_request_codecs_with_filters.yaml @@ -0,0 +1,38 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - pyradios/2.0.0 + method: GET + uri: https://nl1.api.radio-browser.info/json/codecs/mp3 + response: + body: + string: '[{"name":"MP3","stationcount":27967},{"name":"MP3,H.264","stationcount":14}]' + headers: + Access-Control-Allow-Headers: + - origin, x-requested-with, content-type, User-Agent + Access-Control-Allow-Methods: + - GET,POST + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '76' + Content-Type: + - application/json + Date: + - Wed, 25 Oct 2023 06:13:08 GMT + Server: + - nginx/1.18.0 (Ubuntu) + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_radio_browser/test_request_countrycodes_with_filters.yaml b/tests/cassettes/test_radio_browser/test_request_countrycodes_with_filters.yaml new file mode 100644 index 0000000..f0626fd --- /dev/null +++ b/tests/cassettes/test_radio_browser/test_request_countrycodes_with_filters.yaml @@ -0,0 +1,38 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - pyradios/2.0.0 + method: GET + uri: https://nl1.api.radio-browser.info/json/countrycodes/BR + response: + body: + string: '[{"name":"BR","stationcount":953}]' + headers: + Access-Control-Allow-Headers: + - origin, x-requested-with, content-type, User-Agent + Access-Control-Allow-Methods: + - GET,POST + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '34' + Content-Type: + - application/json + Date: + - Wed, 25 Oct 2023 06:13:07 GMT + Server: + - nginx/1.18.0 (Ubuntu) + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_radio_browser/test_request_languages_with_filters.yaml b/tests/cassettes/test_radio_browser/test_request_languages_with_filters.yaml new file mode 100644 index 0000000..c116145 --- /dev/null +++ b/tests/cassettes/test_radio_browser/test_request_languages_with_filters.yaml @@ -0,0 +1,38 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - pyradios/2.0.0 + method: GET + uri: https://nl1.api.radio-browser.info/json/languages/portuguese + response: + body: + string: '[{"name":"brazilian portuguese","iso_639":null,"stationcount":378},{"name":"portuguese","iso_639":"pt","stationcount":562}]' + headers: + Access-Control-Allow-Headers: + - origin, x-requested-with, content-type, User-Agent + Access-Control-Allow-Methods: + - GET,POST + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '123' + Content-Type: + - application/json + Date: + - Wed, 25 Oct 2023 06:13:09 GMT + Server: + - nginx/1.18.0 (Ubuntu) + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_radio_browser/test_request_states_with_filters.yaml b/tests/cassettes/test_radio_browser/test_request_states_with_filters.yaml new file mode 100644 index 0000000..6bebfdb --- /dev/null +++ b/tests/cassettes/test_radio_browser/test_request_states_with_filters.yaml @@ -0,0 +1,38 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - pyradios/2.0.0 + method: GET + uri: https://nl1.api.radio-browser.info/json/states/Brazil/Paran%C3%A1 + response: + body: + string: "[{\"name\":\"Cascavel, Parana\",\"country\":\"Brazil\",\"stationcount\":1},{\"name\":\"Parana\",\"country\":\"Brazil\",\"stationcount\":16},{\"name\":\"Paran\xE1(Brazil)\",\"country\":\"Brazil\",\"stationcount\":13}]" + headers: + Access-Control-Allow-Headers: + - origin, x-requested-with, content-type, User-Agent + Access-Control-Allow-Methods: + - GET,POST + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '184' + Content-Type: + - application/json + Date: + - Wed, 25 Oct 2023 06:13:09 GMT + Server: + - nginx/1.18.0 (Ubuntu) + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_radio_browser/test_request_stations_by_votes.yaml b/tests/cassettes/test_radio_browser/test_request_stations_by_votes.yaml new file mode 100644 index 0000000..a2fbad0 --- /dev/null +++ b/tests/cassettes/test_radio_browser/test_request_stations_by_votes.yaml @@ -0,0 +1,44 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - pyradios/2.0.0 + method: GET + uri: https://nl1.api.radio-browser.info/json/stations/topvote/1 + response: + body: + string: '[{"changeuuid":"8b62de9b-db82-43dd-9f8a-832a4346448e","stationuuid":"78012206-1aa1-11e9-a80b-52543be04c81","serveruuid":null,"name":"MANGORADIO","url":"http://stream.mangoradio.de/","url_resolved":"https://mangoradio.stream.laut.fm/mangoradio?t302=2023-10-25_06-42-39&uuid=f992e1d3-d33e-45de-978c-e56eb288f9ef","homepage":"https://mangoradio.de/","favicon":"","tags":"mango,mangoradio,mongo,mongoradio,public + radio,webradio","country":"Germany","countrycode":"DE","iso_3166_2":null,"state":"","language":"german","languagecodes":"de","votes":646087,"lastchangetime":"2022-10-02 + 08:26:04","lastchangetime_iso8601":"2022-10-02T08:26:04Z","codec":"MP3","bitrate":128,"hls":0,"lastcheckok":1,"lastchecktime":"2023-10-25 + 04:46:00","lastchecktime_iso8601":"2023-10-25T04:46:00Z","lastcheckoktime":"2023-10-25 + 04:46:00","lastcheckoktime_iso8601":"2023-10-25T04:46:00Z","lastlocalchecktime":"2023-10-25 + 03:44:01","lastlocalchecktime_iso8601":"2023-10-25T03:44:01Z","clicktimestamp":"2023-10-25 + 06:05:42","clicktimestamp_iso8601":"2023-10-25T06:05:42Z","clickcount":10851,"clicktrend":151,"ssl_error":0,"geo_lat":null,"geo_long":null,"has_extended_info":false}]' + headers: + Access-Control-Allow-Headers: + - origin, x-requested-with, content-type, User-Agent + Access-Control-Allow-Methods: + - GET,POST + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '1152' + Content-Type: + - application/json + Date: + - Wed, 25 Oct 2023 06:13:11 GMT + Server: + - nginx/1.18.0 (Ubuntu) + status: + code: 200 + message: OK +version: 1 diff --git a/tests/cassettes/test_radio_browser/test_request_tags_with_filters.yaml b/tests/cassettes/test_radio_browser/test_request_tags_with_filters.yaml new file mode 100644 index 0000000..84bdd81 --- /dev/null +++ b/tests/cassettes/test_radio_browser/test_request_tags_with_filters.yaml @@ -0,0 +1,38 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - pyradios/2.0.0 + method: GET + uri: https://nl1.api.radio-browser.info/json/tags/drum%20and%20bass + response: + body: + string: '[{"name":"drum and bass","stationcount":71}]' + headers: + Access-Control-Allow-Headers: + - origin, x-requested-with, content-type, User-Agent + Access-Control-Allow-Methods: + - GET,POST + Access-Control-Allow-Origin: + - '*' + Connection: + - keep-alive + Content-Length: + - '44' + Content-Type: + - application/json + Date: + - Wed, 25 Oct 2023 06:13:10 GMT + Server: + - nginx/1.18.0 (Ubuntu) + status: + code: 200 + message: OK +version: 1 diff --git a/tests/test_radio_browser.py b/tests/test_radio_browser.py index ea376d1..91ea76c 100644 --- a/tests/test_radio_browser.py +++ b/tests/test_radio_browser.py @@ -74,10 +74,10 @@ def test_station_struct(rb, station_struct): """ Checks if the keys in the API response structure have changed. - Note: This test is more about the API service implmentation, than - it is about this python library. + Note: This test primarily assesses the implementation of the API + service, rather than focusing on this Python library. - See details: + For detailed information, refer to: https://de1.api.radio-browser.info/#Struct_station """ stationuuid = "d97b5842-8e9b-46cc-85f0-d2dff6738c7c" @@ -89,7 +89,6 @@ def test_station_struct(rb, station_struct): @responses.activate def test_request_station_click_counter(rb): - expected = { "ok": True, "message": "retrieved station url", @@ -117,7 +116,6 @@ def test_request_station_click_counter(rb): @responses.activate def test_request_countrycodes(rb): - expected = [{"name": "AD", "stationcount": 5}] responses.add( responses.GET, @@ -125,61 +123,45 @@ def test_request_countrycodes(rb): json=expected, status=200, ) - resp = rb.countrycodes() + assert len(resp) > 0, "at least one country should be in the response" assert "name" in resp[0] assert "stationcount" in resp[0] assert resp == expected +@pytest.mark.vcr() def test_request_countrycodes_with_filters(rb): - - # expected = [{"name": "BR", "stationcount": 607}] - resp = rb.countrycodes(code="BR") + assert len(resp) > 0, "at least one country should be in the response" assert resp[0]["name"] == "BR" +@pytest.mark.vcr() def test_request_codecs(rb): - - # expected = [{"name": "MP3", "stationcount": 16620}] - resp = rb.codecs() + assert len(resp) > 0, "at least one codec should be in the response" assert "name" in resp[0] assert "stationcount" in resp[0] -# @responses.activate +@pytest.mark.vcr() def test_request_codecs_with_filters(rb): """ This test runs against a subset of the API response, with the sole purpose of ensuring the behavior of the filter mechanism of the tested method. """ - # subset of the API response for testing purposes - payload = [ - {'name': 'AAC', 'stationcount': 2226}, - {'name': 'MP3', 'stationcount': 19678}, - {'name': 'MP3,H.264', 'stationcount': 6}, - {'name': 'OGG', 'stationcount': 265}, - {'name': 'UNKNOWN', 'stationcount': 1827}, - - ] - responses.add( - responses.GET, - BASE_URL + "json/codecs/mp3", - json=payload, - status=200, - ) - resp = rb.codecs(codec="mp3") + assert len(resp) == 2 assert resp[0]["name"] == "MP3", "only one codec should be in the response" +@pytest.mark.vcr() def test_request_states_with_filters(rb): # Note: `country` and `state` should be provided in "titlecased", # like so: `str().title()` @@ -191,13 +173,8 @@ def test_request_states_with_filters(rb): assert "stationcount" in resp[0] +@pytest.mark.vcr() def test_request_languages_with_filters(rb): - - # expected = [ - # {"name": "brazilian portuguese", "stationcount": 8,}, - # {"name": "portuguese", "stationcount": 638,}, - # ] - resp = rb.languages(language="portuguese") assert len(resp) > 0, "at least one language should be in the response" @@ -205,16 +182,8 @@ def test_request_languages_with_filters(rb): assert "stationcount" in resp[0] -# @responses.activate +@pytest.mark.vcr() def test_request_tags_with_filters(rb): - - # expected = [{"name": "drum and bass", "stationcount": 73,}] - # responses.add( - # responses.GET, - # BASE_URL + "json/tags/drum%20and%20bass", - # json=expected, - # status=200, - # ) resp = rb.tags(tag="Drum and Bass") assert len(resp) > 0, "at least one tag should be in the response" @@ -222,6 +191,7 @@ def test_request_tags_with_filters(rb): assert "stationcount" in resp[0] +@pytest.mark.vcr() def test_request_stations_by_votes(rb): resp = rb.stations_by_votes(1) assert len(resp) == 1, "exactly one station should be in the response"