"""Integration tests for API endpoints.""" from urllib.parse import urlencode import pytest from sound_recordings import config from tests.integration.request import request_get_cache class TestHello(object): """Test hello endpoint.""" @pytest.fixture def response(self): """Return response.""" return request_get_cache(config.HEALTH_CHECK_URL) def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) def test_returns_payload(self, response): """Test returns correct payload.""" assert response.json() == {"status": "ok"} class TestTopSoundRecordings(object): """Test top sound recordings endpoint.""" @pytest.fixture def response(self, request_headers): """Return response.""" return request_get_cache( config.TOP_SOUND_RECORDINGS_URL, headers=request_headers ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) def test_returns_items(self, payload): """Test returns items.""" assert "items" in payload def test_items_return_list(self, payload): """Test items return list.""" assert isinstance(payload["items"], list) @pytest.mark.parametrize( "sound_recording_field", ["isrc", "streams", "growth_percentage"] ) def test_returns_sound_recording_fields(self, sound_recording_field, payload): """Test returns track fields.""" assert sound_recording_field in payload["items"][0] @pytest.fixture def response_with_params(self, request_headers): """Return response.""" params = ( "?limit=10&offset=0&country_code=UA&country_code=NO" "&country_code=DE&country_code=US&country_code=GB" "&order_by=streams_1_day" ) return request_get_cache( config.TOP_SOUND_RECORDINGS_URL + params, headers=request_headers ) @pytest.fixture def payload_with_params(self, response_with_params): """Return payload.""" return response_with_params.json() def test_succeeds_with_params(self, response_with_params): """Test successful response.""" assert response_with_params.status_code == 200, "Reason: {}, URL: {}".format( response_with_params.reason, response_with_params.url ) def test_returns_items_with_params(self, payload_with_params): """Test returns items.""" assert "items" in payload_with_params def test_items_return_list_with_params(self, payload_with_params): """Test items return list.""" assert isinstance(payload_with_params["items"], list) @pytest.mark.parametrize( "sound_recording_field", ["isrc", "streams", "growth_percentage"] ) def test_returns_sound_recording_fields_with_params( self, sound_recording_field, payload_with_params ): """Test returns track fields.""" assert sound_recording_field in payload_with_params["items"][0] class TestPlacements(object): """Test sound recording placements endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "DED831000251" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" return request_get_cache( config.PLACEMENTS_URL.replace("", isrc), headers=request_headers ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("placements_field", ["sources", "items", "isrc"]) def test_returns_correct_fields(self, placements_field, payload): """Test returns correct fields.""" assert placements_field in payload @pytest.fixture def response_paginated(self, isrc, request_headers): """Return response.""" query_string = urlencode([("limit", 25)] + [("offset", 0)]) return request_get_cache( config.PLACEMENTS_URL.replace("", isrc) + "?" + query_string, headers=request_headers, ) def test_succeeds_paginated(self, response_paginated): """Test successful response.""" assert response_paginated.status_code == 200, "Reason: {}, URL: {}".format( response_paginated.reason, response_paginated.url ) class TestPlacementsArtistProfile(object): """Test sound recording placements endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.PLACEMENTS_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("placements_field", ["sources", "items", "isrc"]) def test_returns_correct_fields(self, placements_field, payload): """Test returns correct fields.""" assert placements_field in payload class TestStreams(object): """Test sound recording source of streams endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" return request_get_cache( config.STREAMS_URL.replace("", isrc), headers=request_headers ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("streams_field", ["stores", "sources", "aggregate"]) def test_returns_correct_fields(self, streams_field, payload): """Test returns correct fields.""" assert streams_field in payload @pytest.mark.parametrize("streams_field", ["streams", "skipRate", "saves", "date"]) def test_returns_correct_fields_streams(self, streams_field, payload): """Test returns correct fields.""" for item in payload["aggregate"]["items"]: assert streams_field in item class TestStreamsArtistProfile(object): """Test sound recording streams endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.STREAMS_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def dynamic_response(self, isrc, artist_profiles_request_headers): """Return response.""" country_param = "?country_code=US" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.STREAMS_URL.replace("", isrc) + country_param + date_param, headers=artist_profiles_request_headers, ) @pytest.fixture def store_filtered_response(self, isrc, artist_profiles_request_headers): """Return response.""" country_param = "?country_code=US" store_param = "&store_ids=1&store_ids=286" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.STREAMS_URL.replace("", isrc) + country_param + date_param + store_param, headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "sound_recording_streams_field", ["isrc", "stores", "aggregate"] ) def test_returns_correct_fields(self, sound_recording_streams_field, payload): """Test returns correct fields.""" assert sound_recording_streams_field in payload @pytest.fixture def dynamic_payload(self, dynamic_response): """Return payload.""" return dynamic_response.json() def test_dynamic_params_succeeds(self, dynamic_response): """Test successful response.""" assert dynamic_response.status_code == 200, "Reason: {}, URL: {}".format( dynamic_response.reason, dynamic_response.url ) @pytest.mark.parametrize( "sound_recording_streams_field", ["isrc", "stores", "aggregate"] ) def test_dynamic_params_return_correct_fields( self, sound_recording_streams_field, payload ): """Test returns correct fields.""" assert sound_recording_streams_field in payload class TestDownloads(object): """Test sound recording streams endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.DOWNLOADS_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def dynamic_response(self, isrc, artist_profiles_request_headers): """Return response.""" country_param = "?country_code=US" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.DOWNLOADS_URL.replace("", isrc) + country_param + date_param, headers=artist_profiles_request_headers, ) @pytest.fixture def store_filtered_response(self, isrc, artist_profiles_request_headers): """Return response.""" country_param = "?country_code=US" store_param = "&store_ids=1&store_ids=286" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.DOWNLOADS_URL.replace("", isrc) + country_param + date_param + store_param, headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "sound_recording_downloads_field", ["isrc", "stores", "aggregate"] ) def test_returns_correct_fields(self, sound_recording_downloads_field, payload): """Test returns correct fields.""" assert sound_recording_downloads_field in payload @pytest.fixture def dynamic_payload(self, dynamic_response): """Return payload.""" return dynamic_response.json() def test_dynamic_params_succeeds(self, dynamic_response): """Test successful response.""" assert dynamic_response.status_code == 200, "Reason: {}, URL: {}".format( dynamic_response.reason, dynamic_response.url ) @pytest.mark.parametrize( "sound_recording_downloads_field", ["isrc", "stores", "aggregate"] ) def test_dynamic_params_return_correct_fields( self, sound_recording_downloads_field, payload ): """Test returns correct fields.""" assert sound_recording_downloads_field in payload @pytest.fixture def store_filtered_payload(self, store_filtered_response): """Return payload.""" return store_filtered_response.json() def test_store_filtered_params_succeeds(self, store_filtered_response): """Test successful response.""" assert store_filtered_response.status_code == 200, "Reason: {}, URL: {}".format( store_filtered_response.reason, store_filtered_response.url ) @pytest.mark.parametrize( "sound_recording_downloads_field", ["isrc", "stores", "aggregate"] ) def test_store_filtered_params_return_correct_fields( self, sound_recording_downloads_field, store_filtered_payload ): """Test returns correct fields.""" assert sound_recording_downloads_field in store_filtered_payload def test_store_filtered_stores_empty(self, store_filtered_payload): """Test returns correct fields.""" assert store_filtered_payload["stores"] == [] class TestDownloadsAll(object): """Test downloads-all endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "GBUM71105426" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.DOWNLOADS_ALL_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("downloads_all_fields", ["isrc", "items"]) def test_returns_correct_fields(self, downloads_all_fields, payload): """Test returns correct fields.""" assert downloads_all_fields in payload class TestDownloadsByStore(object): """Test downloads-by-store endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "GBUM71105426" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.DOWNLOADS_BY_STORE_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("downloads_by_store_fields", ["isrc", "stores"]) def test_returns_correct_fields(self, downloads_by_store_fields, payload): """Test returns correct fields.""" assert downloads_by_store_fields in payload class TestDownloadsByProduct(object): """Test sound-recording//downloads-by-product endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "GBUM71105426" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.DOWNLOADS_BY_PRODUCT_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("downloads_by_product_fields", ["isrc", "products"]) def test_returns_correct_fields(self, downloads_by_product_fields, payload): """Test returns correct fields.""" assert downloads_by_product_fields in payload class TestDownloadsByCountry(object): """Test downloads-by-country endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "GBUM71105426" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.DOWNLOADS_BY_COUNTRY_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("downloads_by_country_fields", ["isrc", "countries"]) def test_returns_correct_fields(self, downloads_by_country_fields, payload): """Test returns correct fields.""" assert downloads_by_country_fields in payload class TestSourceOfStreams(object): """Test sound recording source of streams endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" return request_get_cache( config.SOURCE_OF_STREAMS_URL.replace("", isrc), headers=request_headers, ) @pytest.fixture def dynamic_response(self, isrc, request_headers): """Return response.""" country_param = "?country_code=US" store_param = "&store_ids=1&store_ids=286" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.SOURCE_OF_STREAMS_URL.replace("", isrc) + country_param + store_param + date_param, headers=request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() @pytest.fixture def dynamic_payload(self, dynamic_response): """Return payload.""" return dynamic_response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) def test_dynamic_succeeds(self, dynamic_response): """Test successful response.""" assert dynamic_response.status_code == 200, "Reason: {}, URL: {}".format( dynamic_response.reason, dynamic_response.url ) @pytest.mark.parametrize( "source_of_streams_field", ["collection", "passive", "active", "sources"] ) def test_returns_correct_fields(self, source_of_streams_field, payload): """Test returns correct fields.""" assert source_of_streams_field in payload @pytest.mark.parametrize( "source_of_streams_field", ["collection", "passive", "active", "sources"] ) def test_dynamic_returns_correct_fields( self, source_of_streams_field, dynamic_payload ): """Test returns correct fields.""" assert source_of_streams_field in dynamic_payload class TestSourceOfStreamsArtistProfile(object): """Test sound recording source of streams endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" country_param = "?country_code=US" store_param = "&store_ids=1&store_ids=286" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.SOURCE_OF_STREAMS_URL.replace("", isrc) + country_param + store_param + date_param, headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "source_of_streams_field", ["collection", "passive", "active", "sources"] ) def test_returns_correct_fields(self, source_of_streams_field, payload): """Test returns correct fields.""" assert source_of_streams_field in payload class TestStreamsBreakdown(object): """Test streams breakdown endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" country_param = "?country_code=US" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.STREAMS_BREAKDOWN_URL.replace("", isrc) + country_param + date_param, headers=request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "streams_breakdown_field", ["isrc", "source_of_streams", "streams_by_subscription"], ) def test_returns_correct_fields(self, streams_breakdown_field, payload): """Test returns correct fields.""" assert streams_breakdown_field in payload class TestStreamsBreakdownArtistProfile(object): """Test sound recording source of streams endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" country_param = "?country_code=US" store_param = "&store_ids=1&store_ids=286" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.STREAMS_BREAKDOWN_URL.replace("", isrc) + country_param + date_param + store_param, headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "streams_breakdown_field", ["isrc", "source_of_streams", "streams_by_subscription"], ) def test_returns_correct_fields(self, streams_breakdown_field, payload): """Test returns correct fields.""" assert streams_breakdown_field in payload class TestDemographics(object): """Test streams breakdown endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" country_param = "?country_code=US" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.DEMOGRAPHICS_URL.replace("", isrc) + country_param + date_param, headers=request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("demographics_field", ["isrc", "demographics", "sources"]) def test_returns_correct_fields(self, demographics_field, payload): """Test returns correct fields.""" assert demographics_field in payload class TestTopMarkets(object): """Test sound recording top markets endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "DED831000251" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" store_param = "?store_ids=1&store_ids=286" return request_get_cache( config.TOP_MARKETS_URL.replace("", isrc) + store_param, headers=request_headers, ) @pytest.fixture def response_with_countries(self, isrc, request_headers): """Return response.""" params = "?store_ids=1&store_ids=286&country_code=CA" return request_get_cache( config.TOP_MARKETS_URL.replace("", isrc) + params, headers=request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() @pytest.fixture def payload_with_countries(self, response_with_countries): """Return payload.""" return response_with_countries.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("top_markets_field", ["isrc", "sources", "items"]) def test_returns_correct_fields(self, top_markets_field, payload): """Test returns correct fields.""" assert top_markets_field in payload def test_succeeds_with_countries(self, response_with_countries): """Tests successful response with countries.""" response = response_with_countries assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("top_markets_field", ["isrc", "sources", "items"]) def test_returns_correct_fields_with_countries( self, top_markets_field, payload_with_countries ): """Test returns correct fields.""" assert all( [item["country_code"] == "CA" for item in payload_with_countries["items"]] ) assert top_markets_field in payload_with_countries class TestTopMarketsArtistProfile(object): """Test top markets endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" store_param = "?store_ids=1&store_ids=286" return request_get_cache( config.TOP_MARKETS_URL.replace("", isrc) + store_param, headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("top_markets_field", ["isrc", "sources", "items"]) def test_returns_correct_fields(self, top_markets_field, payload): """Test returns correct fields.""" assert top_markets_field in payload class TestArtistProfileSoundRecordingMetadata(object): """Test sound recording metadata endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.SOUND_RECORDING_METADATA_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200 @pytest.mark.parametrize( "sound_recording_metadata_field", ["isrc", "name", "primary_artists", "products"], ) def test_returns_correct_fields(self, sound_recording_metadata_field, payload): """Test returns correct fields.""" assert sound_recording_metadata_field in payload @pytest.mark.parametrize("artist_field", ["artist_type", "artist_name"]) def test_returns_correct_artist_fields(self, artist_field, payload): """Test returns correct artist fields.""" for artist in payload["primary_artists"]: assert artist_field in artist @pytest.mark.parametrize( "product_field", [ "product_id", "product_name", "release_date", "format", "sale_start_date", "primary_artists", ], ) def test_returns_correct_product_fields(self, product_field, payload): """Test returns correct product fields.""" for product in payload["products"]: assert product_field in product class TestSoundRecordingMetadata(object): """Test sound recording metadata endpoint.""" @pytest.fixture def isrc(self): """Mock track isrc.""" return "DED831000251" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" return request_get_cache( config.SOUND_RECORDING_METADATA_URL.replace("", isrc), headers=request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) def test_returns_correct_fields(self, payload): """Test returns correct fields.""" assert "isrc" in payload def test_returns_isrc(self, isrc, payload): """Test returns isrc.""" assert payload["isrc"] == isrc def test_no_products(self, payload): """Test payload has no products.""" assert len(payload["products"]) == 0 class TestDeletedSoundRecordingMetadata(object): """Test sound recording metadata endpoint.""" @pytest.fixture def isrc(self): """Mock track isrc.""" return "DED831000251" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" return request_get_cache( config.SOUND_RECORDING_METADATA_URL.replace("", isrc) + "?include_deleted=true", headers=request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) def test_returns_correct_fields(self, payload): """Test returns correct fields.""" assert "isrc" in payload def test_returns_isrc(self, isrc, payload): """Test returns isrc.""" assert payload["isrc"] == isrc def test_has_deleted_product(self, isrc, payload): """Test returns isrc.""" assert len(payload["products"]) == 1 assert payload["products"][0]["is_deleted"] class TestSubaccountSoundRecordingMetadata(object): """Test track metadata endpoint with subaccount.""" @pytest.fixture def isrc(self): """Mock track isrc.""" return "DED831000251" @pytest.fixture def response(self, isrc, request_headers): """Return response.""" return request_get_cache( config.SOUND_RECORDING_METADATA_URL.replace("", isrc), headers=request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) def test_returns_isrc(self, isrc, payload): """Test returns isrc.""" assert payload["isrc"] == isrc @pytest.mark.parametrize( "track_metadata_field", ["isrc", "artist_name", "name", "products", "primary_artists"], ) def test_returns_correct_fields(self, track_metadata_field, payload): """Test returns correct fields.""" assert track_metadata_field in payload def test_does_not_contain_subaccount_field(self, payload): """Test does not contain subaccount field.""" assert "subaccount" not in payload class TestDateRanges: """Test date ranges on streams breakdown endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response_start_end_date(self, isrc, request_headers): """Return response.""" date_param = "?start_date=2019-11-01&end_date=2019-12-01" return request_get_cache( config.STREAMS_BREAKDOWN_URL.replace("", isrc) + date_param, headers=request_headers, ) @pytest.fixture def response_start_date_days(self, isrc, request_headers): """Return response.""" date_param = "?start_date=2019-11-01&days=30" return request_get_cache( config.STREAMS_BREAKDOWN_URL.replace("", isrc) + date_param, headers=request_headers, ) @pytest.fixture def response_start_date_days_back(self, isrc, request_headers): """Return response.""" date_param = "?start_date=2019-11-30&days=-30" return request_get_cache( config.STREAMS_BREAKDOWN_URL.replace("", isrc) + date_param, headers=request_headers, ) @pytest.fixture def response_highwatermark_days(self, isrc, request_headers): """Return response.""" date_param = "?start_date=HIGHWATERMARK&days=30" return request_get_cache( config.STREAMS_BREAKDOWN_URL.replace("", isrc) + date_param, headers=request_headers, ) @pytest.fixture def response_highwatermark_days_back(self, isrc, request_headers): """Return response.""" date_param = "?start_date=HIGHWATERMARK&days=-30" return request_get_cache( config.STREAMS_BREAKDOWN_URL.replace("", isrc) + date_param, headers=request_headers, ) def test_succeeds_start_end_date(self, response_start_end_date): """Test successful response.""" assert response_start_end_date.status_code == 200, "Reason: {}, URL: {}".format( response_start_end_date.reason, response_start_end_date.url ) def test_succeeds_start_date_days(self, response_start_date_days): """Test successful response.""" assert ( response_start_date_days.status_code == 200 ), "Reason: {}, URL: {}".format( response_start_date_days.reason, response_start_date_days.url ) def test_succeeds_start_date_days_back(self, response_start_date_days_back): """Test successful response.""" assert ( response_start_date_days_back.status_code == 200 ), "Reason: {}, URL: {}".format( response_start_date_days_back.reason, response_start_date_days_back.url ) def test_succeeds_highwatermark_days(self, response_highwatermark_days): """Test successful response.""" assert ( response_highwatermark_days.status_code == 200 ), "Reason: {}, URL: {}".format( response_highwatermark_days.reason, response_highwatermark_days.url ) def test_succeeds_highwatermark_days_back(self, response_highwatermark_days_back): """Test successful response.""" assert ( response_highwatermark_days_back.status_code == 200 ), "Reason: {}, URL: {}".format( response_highwatermark_days_back.reason, response_highwatermark_days_back.url, ) class TestPlaylists(object): """Test playlists endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return reponse.""" return request_get_cache( config.PLAYLISTS_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "sound_recording_playlists_field", ["isrc", "playlists", "total_playlist_streams"], ) def test_returns_correct_fields(self, sound_recording_playlists_field, payload): """Test returns correct fields.""" assert sound_recording_playlists_field in payload @pytest.fixture def dynamic_response(self, isrc, artist_profiles_request_headers): """Return response.""" country_param = "?country_code=US" date_param = "&start_date=2019-11-01&days=28" return request_get_cache( config.PLAYLISTS_URL.replace("", isrc) + country_param + date_param, headers=artist_profiles_request_headers, ) @pytest.fixture def dynamic_payload(self, dynamic_response): """Return payload.""" return dynamic_response.json() def test_dynamic_params_succeeds(self, dynamic_response): """Test successful response.""" assert dynamic_response.status_code == 200, "Reason: {}, URL: {}".format( dynamic_response.reason, dynamic_response.url ) @pytest.mark.parametrize( "sound_recording_playlists_field", ["isrc", "playlists", "total_playlist_streams"], ) def test_dynamic_params_return_correct_fields( self, sound_recording_playlists_field, payload ): """Test returns correct fields.""" assert sound_recording_playlists_field in payload class TestTopCountriesStreams(object): """Test top-countries endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return reponse.""" return request_get_cache( config.TOP_COUNTRIES_STREAMS_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def dynamic_response(self, isrc, artist_profiles_request_headers): """Return response.""" date_param = "?start_date=2019-11-01&days=28" return request_get_cache( config.TOP_COUNTRIES_STREAMS_URL.replace("", isrc) + date_param, headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "sound_recording_top_countries_field", ["isrc", "top_countries", "sources"] ) def test_returns_correct_fields(self, sound_recording_top_countries_field, payload): """Test returns correct fields.""" assert sound_recording_top_countries_field in payload @pytest.fixture def dynamic_payload(self, dynamic_response): """Return payload.""" return dynamic_response.json() def test_dynamic_params_succeeds(self, dynamic_response): """Test successful response.""" assert dynamic_response.status_code == 200, "Reason: {}, URL: {}".format( dynamic_response.reason, dynamic_response.url ) @pytest.mark.parametrize( "sound_recording_top_countries_field", ["isrc", "top_countries", "sources"] ) def test_dynamic_params_return_correct_fields( self, sound_recording_top_countries_field, payload ): """Test returns correct fields.""" assert sound_recording_top_countries_field in payload class TestTopCountriesDownloads(object): """Test top-countries endpoint.""" @pytest.fixture def isrc(self): """Mock sound recording isrc.""" return "QM6P41952433" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return reponse.""" return request_get_cache( config.TOP_COUNTRIES_DOWNLOADS_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def dynamic_response(self, isrc, artist_profiles_request_headers): """Return response.""" date_param = "?start_date=2019-11-01&days=28" return request_get_cache( config.TOP_COUNTRIES_DOWNLOADS_URL.replace("", isrc) + date_param, headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize( "sound_recording_top_countries_field", ["isrc", "top_countries", "sources"] ) def test_returns_correct_fields(self, sound_recording_top_countries_field, payload): """Test returns correct fields.""" assert sound_recording_top_countries_field in payload @pytest.fixture def dynamic_payload(self, dynamic_response): """Return payload.""" return dynamic_response.json() def test_dynamic_params_succeeds(self, dynamic_response): """Test successful response.""" assert dynamic_response.status_code == 200, "Reason: {}, URL: {}".format( dynamic_response.reason, dynamic_response.url ) @pytest.mark.parametrize( "sound_recording_top_countries_field", ["isrc", "top_countries", "sources"] ) def test_dynamic_params_return_correct_fields( self, sound_recording_top_countries_field, payload ): """Test returns correct fields.""" assert sound_recording_top_countries_field in payload class TestStreamsBySourceOfStreams(object): """Test streams-by-sos endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "DED831000251" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.STREAMS_BY_SOS_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("streams_by_sos_fields", ["isrc", "source_of_streams"]) def test_returns_correct_fields(self, streams_by_sos_fields, payload): """Test returns correct fields.""" assert streams_by_sos_fields in payload class TestStreamsByStore(object): """Test streams-by-store endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "DED831000251" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.STREAMS_BY_STORE_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("streams_by_store_fields", ["isrc", "stores"]) def test_returns_correct_fields(self, streams_by_store_fields, payload): """Test returns correct fields.""" assert streams_by_store_fields in payload class TestStreamsByProduct(object): """Test streams-by-product endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "DED831000251" @pytest.fixture def response(self, isrc, insights_employee_request_headers): """Return response.""" return request_get_cache( config.STREAMS_BY_PRODUCT_URL.replace("", isrc), headers=insights_employee_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("streams_by_product_fields", ["isrc", "products"]) def test_returns_correct_fields(self, streams_by_product_fields, payload): """Test returns correct fields.""" assert streams_by_product_fields in payload class TestStreamsAll(object): """Test streams-all endpoint.""" @pytest.fixture def isrc(self): """Mock ISRC.""" return "DED831000251" @pytest.fixture def response(self, isrc, artist_profiles_request_headers): """Return response.""" return request_get_cache( config.STREAMS_ALL_URL.replace("", isrc), headers=artist_profiles_request_headers, ) @pytest.fixture def payload(self, response): """Return payload.""" return response.json() def test_succeeds(self, response): """Test successful response.""" assert response.status_code == 200, "Reason: {}, URL: {}".format( response.reason, response.url ) @pytest.mark.parametrize("streams_all_fields", ["isrc", "items"]) def test_returns_correct_fields(self, streams_all_fields, payload): """Test returns correct fields.""" assert streams_all_fields in payload