"""Common fixtures for Spotify Snowflake.""" from collections import defaultdict, namedtuple from itertools import product import pytest from feed_ingestion.flows.spotify import config @pytest.fixture def mock_temp_staging_raw_names(): """Generate temp_staging_raw table names.""" temp_staging_raw_names = defaultdict(dict) for licensor in config.spotify_api_licensors: for report in config.reports: temp_staging_raw_names[licensor][report] = ( config.temp_staging_raw_table.format( date='20171116', report=report, licensor=licensor)) return temp_staging_raw_names @pytest.fixture def mock_common_tables(): """Return common table names.""" CommonTables = namedtuple( 'CommonTables', 'report_name, transitional_temp_table, staging_table') common_tables = [ CommonTables( 'tracks', 'transitional_temp_table_tracks_20171116', 'spotify_tracks')] return common_tables @pytest.fixture def mock_reports_status_names(): """Return reports and feed statuses for them.""" reports_status_names = defaultdict(dict) reports = dict(config.reports) for licensor, report_name in product( config.spotify_api_licensors, reports): report_feed_name = '_'.join([config.feed_name, licensor, report_name]) reports_status_names[licensor][report_name] = report_feed_name return reports_status_names @pytest.fixture def mock_reports_status_names_without_download_only(): """Return reports and feed statuses for them.""" reports_status_names = defaultdict(dict) reports = { report for report in config.reports if report not in config.download_only_reports} for licensor, report_name in product( config.spotify_api_licensors, reports): report_feed_name = '_'.join([config.feed_name, licensor, report_name]) reports_status_names[licensor][report_name] = report_feed_name return reports_status_names @pytest.fixture def mock_archive_paths(): """Return common table names.""" archive_paths = defaultdict(dict) for licensor, report_name in product( config.spotify_api_licensors, config.reports): archive_paths[licensor][report_name] = ( 'SpotifyV2/archives/2017-11-16/{report_name}/{licensor}/'.format( report_name=report_name, licensor=licensor)) return archive_paths @pytest.fixture def mock_drop_paths(): """Return common table names.""" drop_paths = defaultdict(dict) for licensor, report_name in product( config.spotify_api_licensors, config.reports): drop_paths[licensor][report_name] = ( 'feed-drop/SpotifyV2/2017-11-16/{report_name}/{licensor}/'.format( report_name=report_name, licensor=licensor)) return drop_paths