import pytest import allure from datetime import datetime from assertpy import assert_that from src.helpers.utils import calc_days_ago entity_type = 'artist' input_spotify_followers = [ (0, 1000), (1000, 5000), (5000, 10000), (10000, 25000), (25000, 50000), (50000, 100000), (100000, 250000), (250000, 500000), (500000, 1000000), (1000000, 5000000), (5000000, 100000000000) ] input_spotify_min_tracks = [5, 10, 25, 50, 100, 250, 500, 1000] input_spotify_listeners = [ (0, 100), (100, 1000), (1000, 5000), (5000, 10000), (10000, 25000), (25000, 50000), (50000, 100000), (100000, 250000), (250000, 500000), (500000, 1000000), (1000000, 5000000), (5000000, 100000000000), ] input_spotify_popularity = [ (0, 10), (10, 20), (20, 30), (30, 40), (40, 50), (50, 60), (60, 70), (70, 80), (80, 90), (90, 100), ] input_spotify_latest_release = [7, 28, 56, 84] @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1603") @pytest.mark.parametrize("min_val, max_val", input_spotify_followers) def test_spotify_followers(api, min_val, max_val): data = {"spotify": {"min_followers": min_val, "max_followers": max_val}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: tested_value = float(entity['spotify']['followers']['current_value']) api.check_entity_in_range(entity, tested_value, min_val, max_val) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1603") @pytest.mark.parametrize("min_val", input_spotify_min_tracks) def test_spotify_min_tracks(api, min_val): data = {"spotify": {"min_tracks": min_val}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: tested_value = float(entity['spotify']['tracks']['current_value']) api.check_entity_in_range(entity, tested_value) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1603") @pytest.mark.parametrize("min_val, max_val", input_spotify_listeners) def test_spotify_listeners(api, min_val, max_val): data = {"spotify": {"min_listeners": min_val, "max_listeners": max_val}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: tested_value = float(entity['spotify']['listeners']['current_value']) api.check_entity_in_range(entity, tested_value, min_val, max_val) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1603") @pytest.mark.parametrize("min_val, max_val", input_spotify_popularity) def test_spotify_popularity(api, min_val, max_val): data = {"spotify": {"min_popularity": min_val, "max_popularity": max_val}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: tested_value = float(entity['spotify']['popularity']['current_value']) api.check_entity_in_range(entity, tested_value, min_val, max_val) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1603") @pytest.mark.parametrize("max_val", input_spotify_latest_release) def test_spotify_latest_release(api, max_val): data = {"spotify": {"min_latest_release_days": max_val}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: latest_release_date = entity['spotify']['latest_release_date'] days_ago = calc_days_ago(latest_release_date, '%Y-%m-%d') tested_value = float(days_ago) api.check_entity_in_range(entity, tested_value, max_val=max_val) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1603") def test_spotify_chart_type(api): data = {"spotify": {"chart_type": "LISTENERS"}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: actual_chart_type = entity['spotify']['chart_type'] assert_that(actual_chart_type == 'listeners').is_true() data = {"spotify": {"chart_type": "POPULARITY"}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: actual_chart_type = entity['spotify']['chart_type'] assert_that(actual_chart_type == 'popularity').is_true() data = {"spotify": {}} entities = api.get_entities(entity_type=entity_type, discovery_data=data) for entity in entities: actual_chart_type = entity['spotify']['chart_type'] assert_that(actual_chart_type == 'followers').is_true()