"""Integration API fixtures.""" from datetime import datetime, timedelta from os import getenv import pytest from tests.consts.api import USER_PROFILES from tests.integration.utils.user import QAUser # TODO include 7 days once snowflake sync job is up # TODO include 365 days once demo and geo insights don't time out @pytest.fixture(scope='module', params=[30]) def dates_from_today(request): """Get current date ranges.""" date_format = '%Y-%m-%d' time_delta = timedelta(days=request.param) to_date = datetime.now() from_date = to_date - time_delta return {'from': from_date.strftime(date_format), 'to': to_date.strftime(date_format)} @pytest.fixture(scope='session', params=[('2018-05-17', '2018-05-24'), ('2018-04-24', '2018-05-24'), ('2017-05-24', '2018-05-24')]) def dates(request): """Get fixed date ranges.""" return {'from': request.param[0], 'to': request.param[1]} @pytest.fixture(scope='session', params=[('2021-08-17', '2021-08-24'), ('2021-07-24', '2021-08-24'), ('2021-06-24', '2021-07-24')]) def demographics_insights_dates(request): """Get fixed date ranges.""" return {'from': request.param[0], 'to': request.param[1]} @pytest.fixture(scope='session') def automation_user(request): """Get the automation contact under test label.""" return QAUser(38271) @pytest.fixture(scope='module', params=[ user_id for user_id in USER_PROFILES if 'api' in USER_PROFILES[user_id]['test_types']]) def user(request): """Get a test user.""" return QAUser(request.param) @pytest.fixture(scope='module') def playlist_links(request, user): """Get playlist links associated with a vendor id.""" playlist_links = USER_PROFILES[int(user.user_id)].get('playlist_links') return playlist_links[0] @pytest.fixture(scope='module') def isrcs(request, user, isrc_count): """Get ISRCs associated with a vendor id.""" load_test_vendor = USER_PROFILES.get(int(user.user_id)) if not load_test_vendor: return '' isrcs = load_test_vendor.get('isrcs') return ','.join(isrcs[: isrc_count]) # TODO get range count from # of ISRCs @pytest.fixture(scope='module', params=list(range(7))) def isrc_count(request): """Get how many ISRCs to be included in request.""" return request.param @pytest.fixture(scope='module') def artist_ids(request, user, artist_count): """Get artist_ids associated with a vendor id.""" load_test_vendor = USER_PROFILES.get(int(user.user_id)) if not load_test_vendor: return '' artist_ids = load_test_vendor.get('artist_ids') return ','.join(artist_ids[: artist_count]) # TODO get range count from # of artists @pytest.fixture(scope='module', params=list(range(7))) def artist_count(request): """Get how many artists to be included in request.""" return request.param @pytest.fixture(scope='module', params=[1, 286]) def stores(request): """Get the store id.""" return request.param