"""Integration API tests for ows-analytics.""" from os import getenv import pytest from tests.integration.snapshots import SNAPSHOT_TEST_DEMOGRAPHIC_INSIGHTS,\ SNAPSHOT_TEST_GEOGRAPHIC_ORCHARD_REGIONS,\ SNAPSHOT_TEST_PLAYLIST_PLACEMENTS, SNAPSHOT_TEST_STREAM_CHARTS @pytest.mark.skip(reason="CurrentDate tests return 403 errors, the pages are deprecated according to data platform team.") # noqa class TestCurrentDates: """Test API responses with current dates.""" def test_demographic_insights_response(self, user, dates_from_today): """Get demographic insights.""" params = { 'from_date': dates_from_today['from'], 'to_date': dates_from_today['to'], 'stores': 286 } response = user.get_demographic_insights(**params) assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert 'gender_breakdown' in response_body assert 'top_audiences' in response_body assert 'age_breakdown' in response_body def test_stream_charts_response(self, user, dates_from_today, stores): """Test stream charts response.""" params = { 'from_date': dates_from_today['from'], 'to_date': dates_from_today['to'], 'stores': stores } response = user.get_stream_charts(**params) assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert 'streams_from_passive_discovery' in response_body assert 'streams_from_collection_pct' in response_body assert 'streams_from_active_discovery' in response_body assert 'streams_from_collection' in response_body assert 'streams_from_passive_discovery_pct' in response_body assert 'overall_number_of_streams' in response_body assert 'items' in response_body def test_playlist_placements_response(self, user, dates_from_today, stores): """Test playlist placements response.""" params = { 'from_date': dates_from_today['from'], 'to_date': dates_from_today['to'], 'stores': stores } response = user.get_playlist_placements(**params) assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert 'total' in response_body assert 'items' in response_body def test_playlist_metadata_response(self, user, playlist_links): """Test playlist metadata response.""" params = { 'playlist_links': playlist_links } response = user.get_playlist_metadata(**params) assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert type(response_body) is list playlist_followers = response_body[0].get('followers') playlist_image = response_body[0].get('image') playlist_title = response_body[0].get('playlist_title') playlist_author = response_body[0].get('playlist_author') playlist_link = response_body[0].get('playlist_link') assert playlist_followers != '--' assert playlist_image is not None assert playlist_title is not None assert playlist_author is not None assert playlist_link == playlist_links def test_geographic_by_region_response(self, user, dates_from_today): """Test geographic insights by region response.""" params = { 'from_date': dates_from_today['from'], 'to_date': dates_from_today['to'], } response = user.get_geographic_by_region(**params) assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert len(response_body) > 0 assert 'region_name' in response_body.get('items')[0].keys() assert 'region_code' in response_body.get('items')[0].keys() assert 'territory_code' in response_body.get('items')[0].keys() assert 'unique_listeners' in response_body.get('items')[0].keys() assert 'number_of_streams' in response_body.get('items')[0].keys() assert 'total_streams' in response_body assert 'total_listeners' in response_body def test_geographic_by_territory_response(self, user, dates_from_today): """Test geographic insights by territory response.""" params = { 'from_date': dates_from_today['from'], 'to_date': dates_from_today['to'], } response = user.get_geographic_by_territory(**params) assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert len(response_body) > 0 assert 'territory_code' in response_body.get('items')[0].keys() assert 'unique_listeners' in response_body.get('items')[0].keys() assert 'number_of_streams' in response_body.get('items')[0].keys() assert 'total_streams' in response_body assert 'total_listeners' in response_body def test_geographic_orchard_regions_response(self, user, dates_from_today): """Test geographic orchard regions response.""" response = user.get_geographic_orchard_regions() assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert len(response_body) > 0 assert 'region_name' in response_body[0].keys() assert 'region_code' in response_body[0].keys() assert 'territory_code' in response_body[0].keys() def test_get_geographics_latest_date_response(self, user, dates_from_today): """Test geographic orchard latest date response.""" response = user.get_geographics_latest_date() assert response.status_code == 200, '\nReason: {}\nURL: {}'.format( response.reason, response.url) response_body = response.json() assert 'last_activity_date' in response_body class TestFixedDates: """Test API responses with fixed dates.""" def test_stream_charts_response( self, automation_user, dates): """Test stream charts response.""" params = { 'from_date': dates['from'], 'to_date': dates['to'], 'stores': 286 } response = automation_user.get_stream_charts(**params) response_body = response.json() assert response_body == SNAPSHOT_TEST_STREAM_CHARTS[ dates['from'] + dates['to'] ] def test_demographic_insights_response( self, automation_user, demographics_insights_dates): """Get demographic insights.""" params = { 'from_date': demographics_insights_dates['from'], 'to_date': demographics_insights_dates['to'], 'stores': 286 } response = automation_user.get_demographic_insights(**params) response_body = response.json() assert response_body == SNAPSHOT_TEST_DEMOGRAPHIC_INSIGHTS[ demographics_insights_dates[ 'from'] + demographics_insights_dates['to'] ] def test_playlist_placements_response( self, automation_user, dates): """Test playlist placements response.""" params = { 'from_date': dates['from'], 'to_date': dates['to'], 'stores': 286 } response = automation_user.get_playlist_placements(**params) response_body = response.json() assert response_body == SNAPSHOT_TEST_PLAYLIST_PLACEMENTS[ dates['from'] + dates['to'] ] @pytest.mark.skip(reason="The table was updated with the new values, it doesn't make sense to fix the fixture") def test_geographic_orchard_regions_response_fixture( self, automation_user): """Test geographic orchard regions response.""" response = automation_user.get_geographic_orchard_regions() response_body = response.json() assert response_body == SNAPSHOT_TEST_GEOGRAPHIC_ORCHARD_REGIONS