"""conftest. This file gets picked up when running py.test tests: http://pytest.org/latest/writing_plugins.html#conftest """ from datetime import datetime from unittest.mock import MagicMock import uuid import application import boto3 from botocore.signers import CloudFrontSigner from flask import testing import pytest from werkzeug.datastructures import Headers from podcast import config from podcast.connectors import mysql from podcast.constants import analytics as analytics_constants from podcast.logic import email from podcast.logic import megaphone from podcast.models import ows_asset_transcoder as oat from podcast.models import user as user_model from podcast.models.api_campaign import ApiCampaign from podcast.utils import api_utils, signed_urls from tests.utils import db_operations config.ENVIRONMENT = config.TEST_ENVIRONMENT class TestClient(testing.FlaskClient): """Test client implementation with user headers.""" def open(self, *args, **kwargs): # noqa: A003 """Open method.""" user_headers = Headers({ 'Orchard-Identity-UUID': 'Billy' }) content_type_headers = Headers({ 'Content-Type': 'application/json' }) headers = kwargs.pop('headers', Headers()) if isinstance(headers, dict): headers.update(user_headers) headers.update(content_type_headers) else: headers.extend(user_headers) headers.extend(content_type_headers) kwargs['headers'] = headers return super().open(*args, **kwargs) @pytest.fixture def no_user_fixture_client(): """Create an api test client fixture.""" application.app.test_client_class = testing.FlaskClient with application.app.test_client() as client: yield client @pytest.fixture def fixture_client(): """Create an api test client fixture.""" application.app.test_client_class = TestClient with application.app.test_client() as client: yield client application.app.test_client_class = testing.FlaskClient @pytest.fixture(autouse=True) def db_fixture(): """Drop and re-create all the SQLite tables and seed them.""" db_operations.create_tables() db_operations.seed_data() yield db_operations.drop_tables() @pytest.fixture(autouse=True) def mock_cloudfront_config(monkeypatch): """Drop and re-create all the SQLite tables and seed them.""" monkeypatch.setattr(config, 'CLOUDFRONT_PRIVATE_KEY', 'cdn-private-key') monkeypatch.setattr(config, 'CLOUDFRONT_KEY_PAIR_ID', 'cdn-key-id') @pytest.fixture def mock_ows_headers(monkeypatch): """Drop and re-create all the SQLite tables and seed them.""" monkeypatch.setattr(api_utils, 'get_ows_headers', MagicMock( return_value={ 'Orchard-Profile-Type': 'PodcastProfile', 'Orchard-Profile-Id': '13', 'Orchard-User-Id': '12', } )) @pytest.fixture def context(): """Return flask app context, including a mock logger. Returns: AppContext: flask app context, including a mock logger. """ return application.app.app_context() @pytest.fixture def podcast_fixture(): """Return a podcast fixture.""" return dict( id=1, title='title', description='description', slug='slug', copyright='copyright', show_type='episodic', host='BillFrost', owner='CharliePower', email='email', link='link', explicit='explicit', created_by='test_user', updated_by='test_user', language='en', categories=[1], uuid=str(uuid.uuid4()), created_date=datetime.now(), updated_date=datetime.now(), network_id=1, megaphone_id='megaphone_id_1', show_family_id=1, feed_type='public-rss' ) @pytest.fixture def podcast_fixture_2(): """Return a second podcast fixture.""" return dict( id=2, network_id=2, title='alpha title 1', description='description \r\n1. ', slug='sony12345', copyright='copyright', email='email@domain.dom', link='http://domain.dom', explicit='explicit', show_type='serial', owner='Sally', host='Betty', language='en', created_by=1, updated_by=1, created_date=datetime.now(), updated_date=datetime.now(), megaphone_id='6bf5bea4-a1d4-11e6-8dea-b334e2aa4720', categories=[3, 4], uuid=str(uuid.uuid4()), apple_id=1234567890, show_family_id=2, feed_type='public-rss' ) @pytest.fixture def podcast_fixture_3(): """Return a third podcast fixture.""" return dict( id=3, network_id=2, title='alpha title 1', description='description \r\n1. ', slug='sony12345', copyright='copyright', email='email@domain.dom', link='http://domain.dom', explicit='explicit', show_type='serial', owner='Sally', host='Betty', language='en', created_by=1, updated_by=1, created_date=datetime.now(), updated_date=datetime.now(), megaphone_id='6bf5bea4-a1d4-11e6-8dea-b334e2aa4723', categories=[3, 4], uuid=str(uuid.uuid4()), apple_id=1234567890, show_family_id=2, feed_type='private-rss' ) @pytest.fixture def podcast_fixture_4(): """Return a forth podcast fixture.""" return dict( id=4, network_id=2, title='alpha title 4', description='description \r\n4. ', slug='sony12345', copyright='copyright', email='email@domain.dom', link='http://domain.dom', explicit='explicit', show_type='serial', owner='Sally', host='Betty', language='en', created_by=1, updated_by=1, created_date=datetime.now(), updated_date=datetime.now(), megaphone_id='6bf5bea4-a1d4-11e6-8dea-b334e2aa4724', categories=[3, 4], uuid=str(uuid.uuid4()), apple_id=1234567890, show_family_id=2, feed_type='apple-subscription' ) @pytest.fixture def show_family_fixture(): """Return a show_family fixture.""" return dict( id=1, title='title', network_id=1, created_by=1, updated_by=1, created_date='2023-01-01 22:00:00', updated_date='2023-01-01 22:00:00', is_deleted=False ) @pytest.fixture def second_show_family_fixture(): """Return a second show_family fixture.""" return dict( id=2, title='second show family', network_id=2, created_by=1, updated_by=1, created_date='2023-07-15 22:00:00', updated_date='2023-07-15 22:00:00', is_deleted=False ) @pytest.fixture def third_show_family_fixture(): """Return a third show_family fixture.""" return dict( id=4, title='4th show family', network_id=2, created_by=1, updated_by=1, created_date='2023-07-15 22:00:00', updated_date='2023-07-15 22:00:00', is_deleted=False ) @pytest.fixture def planned_inventory_fixture(): """Return a planned inventory payload fixture.""" return dict( dates=['2019-11-26T16:52:01.000Z'], pre_rolls=1, post_rolls=2, mid_rolls=0, title_prefix='Draft Episode for ', ) @pytest.fixture def ad_read_fixture(): """Return a ad read payload fixture.""" return dict( title='Ad Title', campaign_id='1', order_id='mp1', advertisement_id='2', roll_type='mid', assignee_ids=[1], copy_url_path='fake/file.pdf', copy_filename='file.pdf', due_date='2019-01-01', rejection_reason='some reason', requires_approval=True ) @pytest.fixture def ad_read_fixture_2(): """Return a second ad read payload fixture.""" return dict( title='Ad Title', campaign_id='1', order_id='mp1', advertisement_id='2', roll_type='mid', assignee_ids=[1, 2, 3, 4, 5, 6], copy_url_path='fake/file.pdf', copy_filename='file.pdf', due_date='2019-01-01', rejection_reason='some reason', requires_approval=True ) @pytest.fixture def new_ad_read_comment_fixture(): """Return create ad read comment payload fixture.""" return dict( ad_action_id=1, comment='test comment' ) @pytest.fixture def ad_read_comment_fixture(): """Return a ad read comment fixture.""" return { 'items': [ { 'id': 1, 'ad_read_id': 111, 'comment': 'hello test comment', 'created_by': 1, 'created_date': '2022-01-17T10:46:50.000Z', 'updated_by': 1, 'updated_date': None } ], 'pagination': { 'total_records': 1 } } @pytest.fixture def episode_fixture(): """Return an episode fixture.""" return dict( id=4, podcast_id=1, title='Episode Title', description='Episode Description', season_number=1, episode_number=1, episode_type='full', content='clean', planned_pre_roll_count=0, planned_mid_roll_count=1, planned_post_roll_count=2, created_by='test_user', updated_by='test_user', insertion_points=[], uuid='dd3ab0f6-a3bb-4635-b76c-bc2afda9fb0d', megaphone_id=None, draft=True, external_id=None, is_reviewed=True, apple_id='episode-apple-id' ) @pytest.fixture def episode_fixture_2(): """Return an episode fixture.""" return dict( id=6, podcast_id=1, title='Episode Title 2', description='Episode Description 2', season_number=1, episode_number=1, episode_type='full', content='clean', planned_pre_roll_count=0, planned_mid_roll_count=1, planned_post_roll_count=2, created_by='test_user', updated_by='test_user', insertion_points=[], uuid='dd3ab0f6-a3bb-4635-b76c-bc2afda9fb0d', megaphone_id=None, draft=True, external_id=None ) @pytest.fixture def episode_fixture_3(): """Return a third episode fixture.""" return dict( id=7, podcast_id=2, title='Episode Title seven', description='Episode Description seven', season_number=1, episode_number=1, episode_type='full', content='clean', planned_pre_roll_count=0, planned_mid_roll_count=1, planned_post_roll_count=2, created_by='test_user', updated_by='test_user', insertion_points=[], uuid='dd3ab0f6-a3bb-4635-b76c-bc2afda9fb11', megaphone_id=None, draft=True, external_id=None, apple_id=1234567890 ) @pytest.fixture def episode_bad_description_fixture(): """Return an episode with bad description fixture.""" return dict( id=4, podcast_id=1, title='Episode with bad data', description='

description3

Learn more about your ad choices.

', season_number=1, episode_number=2, episode_type='full', content='clean', created_by=1, updated_by=2, created_date=datetime.now(), updated_date=datetime.now(), published_date=datetime(2018, 1, 1, 8, 20, 20), megaphone_id='6bf5bea4-a1d4-11e6-8dea-b334e2aa4811', megaphone_uid='mpuid2', draft=True, planned_pre_roll_count=0, planned_mid_roll_count=1, planned_post_roll_count=2, ) @pytest.fixture def episode_replication_status_fixture(): """Return a episode replication status fixture.""" return dict( id=5, original_podcast_id=1, podcast_id=4, original_episode_id=4, episode_id=5, status='initiated', replication_type='bulk', created_timestamp=datetime(2023, 4, 4, 8, 20, 20) ) @pytest.fixture def single_episode_replication_status_fixture(): """Return a single episode replication status fixture.""" return dict( id=3, original_podcast_id=2, original_episode_id=7, podcast_id=4, episode_id=8, status='initiated', replication_type='single', created_timestamp=datetime(2023, 4, 4, 8, 20, 20) ) @pytest.fixture def mock_replicate_episodes_fixture(): """Return a _replicate_episodes success object.""" return dict( original_podcast_id=1, podcast_id=4, original_episode_id=4, episode_id=5 ) @pytest.fixture def mock_replicate_episodes_fixture_2(): """Return a _replicate_episodes success object.""" return dict( original_podcast_id=1, podcast_id=4, original_episode_id=6, episode_id=7 ) @pytest.fixture def mock_replicate_single_episode_fixture(): """Return a _replicate_episode_for_type_single success object.""" return dict( original_podcast_id=2, original_episode_id=7, podcast_id=3, episode_id=8, feed_type='private-rss', original_podcast_feed_type='public-rss' ) @pytest.fixture def mock_replicate_single_episode_fixture_2(): """Return a _replicate_episode_for_type_single 2 success object.""" return dict( original_podcast_id=2, original_episode_id=7, podcast_id=4, episode_id=9, feed_type='apple-subscription', original_podcast_feed_type='public-rss' ) @pytest.fixture def mock_replicate_single_episode_fixture_3(): """Return a _replicate_episode_for_type_single 3 success object.""" return dict( original_podcast_id=2, original_episode_id=7, podcast_id=1, episode_id=6, feed_type='public-rss', original_podcast_feed_type='public-rss' ) @pytest.fixture def network_fixture(): """Return a podcast fixture.""" return dict( id=1, name='Network name', uuid='64756b62-7e5c-4728-895a-2f42f8969e14' ) @pytest.fixture def db_session_fixture(monkeypatch): """Return mocked db session fixture.""" session_object = MagicMock() session_object.commit.return_value = True session_object.rollback.return_value = True monkeypatch.setattr(mysql, 'podcast_db_session', MagicMock( return_value=session_object )) return session_object @pytest.fixture def db_session(): """Return mocked db session fixture.""" with mysql.pod_db_session() as session: yield session @pytest.fixture def mock_admin_user_id(monkeypatch): """Return fixture for user_id extraction.""" monkeypatch.setattr(api_utils, '_get_uuid', MagicMock( return_value='Billy' )) @pytest.fixture def mock_user_id(monkeypatch): """Return fixture for user_id extraction.""" monkeypatch.setattr(api_utils, '_get_uuid', MagicMock( return_value='auth0-test-user-1' )) @pytest.fixture def mock_network_admin_user_id(monkeypatch): """Return fixture for user_id extraction.""" monkeypatch.setattr(api_utils, '_get_uuid', MagicMock( return_value='auth0-network-admin-user' )) @pytest.fixture def mock_podcast_level_user_id(monkeypatch): """Return fixture for user_id extraction.""" monkeypatch.setattr(api_utils, '_get_uuid', MagicMock( return_value='podcast-level-user' )) @pytest.fixture def mock_automation_admin_user_id(monkeypatch): """Return fixture for user_id extraction.""" monkeypatch.setattr(api_utils, '_get_uuid', MagicMock( return_value='automation' )) @pytest.fixture def mock_current_producer_user_id(monkeypatch): """Return fixture for producer user_id extraction.""" monkeypatch.setattr(api_utils, '_get_uuid', MagicMock( return_value='two-network-user' )) @pytest.fixture def mock_current_show_level_user_id(monkeypatch): """Return fixture for show_level_user user_id extraction.""" monkeypatch.setattr(api_utils, '_get_uuid', MagicMock( return_value='auth0-not-admin-user' )) @pytest.fixture def mock_current_user(monkeypatch, mock_user_id): """Mock get_current_user to return normal user.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(1) )) @pytest.fixture def mock_current_read_only_user(monkeypatch, mock_user_id): """Mock get_current_user to return read level producer user.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(14) )) @pytest.fixture def mock_current_admin_user(monkeypatch, mock_admin_user_id): """Mock get_current_user to return org admin user.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(2) )) @pytest.fixture def mock_current_network_admin_user(monkeypatch, mock_network_admin_user_id): """Mock get_current_user to return network admin.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(6) )) @pytest.fixture def mock_current_network_admin_user_second(monkeypatch, mock_network_admin_user_id): """Mock get_current_user to return network admin.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(12) )) @pytest.fixture def mock_current_network_admin_user_all_access(monkeypatch, mock_network_admin_user_id): """Mock get_current_user to return network admin.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(13) )) @pytest.fixture def mock_current_podcast_level_user(monkeypatch, mock_podcast_level_user_id): """Mock get_current_user to return network admin.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(11) )) @pytest.fixture def mock_current_automation_admin_user(monkeypatch, mock_automation_admin_user_id): """Mock get_current_user to return org admin user.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(10) )) @pytest.fixture def mock_current_producer_user(monkeypatch, mock_current_producer_user_id): """Mock get_current_user to return producer.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(8) )) @pytest.fixture def mock_current_show_level_user(monkeypatch, mock_current_show_level_user_id): """Mock get_current_user to return user with show level access.""" monkeypatch.setattr(api_utils, 'get_current_user', MagicMock( return_value=user_model.get_user_by_id(5) )) @pytest.fixture def mock_update_advertisement(monkeypatch): """Mock update_advertisement in megaphone.""" monkeypatch.setattr(ApiCampaign, 'update_advertisement', MagicMock(return_value=None)) @pytest.fixture def mock_audio_assets(monkeypatch): """Mock get audio for ad from oat.""" monkeypatch.setattr(oat, 'get_ad_assets', MagicMock(return_value={'audio_url': 'mockurl.mp3'})) @pytest.fixture def header_user_fixture(): """Return fixture for headers with user_id field.""" return { 'Orchard-Identity-Id': 'Billy' } @pytest.fixture def output_cdn_fixture(monkeypatch): """Set monkeypatched fixture for OUTPUT_CDN_BASE_URL constant.""" monkeypatch.setattr(config, 'OUTPUT_CDN_BASE_URL', 'output.com') @pytest.fixture def participant_fixture(): """Participant fixture.""" return {'name': 'Bill', 'role': 'other', 'participant_id': 1} @pytest.fixture def seasons_fixture(): """Seasons fixture.""" return [ {'number': 1, 'name': 'test season', 'external_id': 'test-id'}, {'number': 2, 'name': 'another season'} ] @pytest.fixture def podcast_1_seasons_fixture(): """Seasons fixture for podcast id=1.""" return [ {'id': 1, 'podcast_id': 1, 'number': 1, 'name': 'test season 1', 'external_id': 'test-id'}, {'id': 2, 'podcast_id': 1, 'number': 2, 'name': 'test season 2', 'external_id': 'test-id'} ] @pytest.fixture def podcast_2_seasons_fixture(): """Seasons fixture for podcast id=1.""" return [ {'id': 3, 'podcast_id': 2, 'number': 1, 'name': 'test season 1', 'external_id': 'test-id'}, {'id': 4, 'podcast_id': 2, 'number': 2, 'name': 'test season 2', 'external_id': 'test-id'} ] @pytest.fixture def podcast_2_seasons_replica_fixture(): """Seasons Replica fixture.""" return [ {'id': 5, 'podcast_id': 2, 'number': 1, 'name': 'test season 1'}, {'id': 6, 'podcast_id': 2, 'number': 2, 'name': 'test season 2'} ] @pytest.fixture def podcast_4_seasons_fixture(): """Podcast 4 seasons Replica fixture.""" return [ {'id': 8, 'podcast_id': 4, 'number': 1, 'name': 'test season 1'}, {'id': 9, 'podcast_id': 4, 'number': 2, 'name': 'test season 2'} ] @pytest.fixture def get_assets_mock(monkeypatch): """Set monkeypatched fixture for assets fetch.""" monkeypatch.setattr(oat, '_get_assets', MagicMock(return_value=[ { 'id': 67, 'user_id': '5e3c422f2e3f230d9a446b57', 'asset_type': 'WAV', 'media_type': 'audio', 'filename': '461f5444_a522_4ff1_b51f_17b699df621b', 'object_id': '1933', 'object_type': 'episode', 'original_filename': 'Super%20Sporm%20(part1)%20copy.wav', 'asset_finals': [ { 'asset_type': 'FLAC', 'asset_subtype': 'none', 'filename': 'a.flac', 'url': 'http://url/a.flac', 'duration': 24384 }, { 'asset_type': 'MP3', 'asset_subtype': 'none', 'filename': 'a.mp3', 'url': 'http://url/b.mp3', 'duration': 24424 } ], 'status': 'encoding_completed' }, { 'id': 70, 'user_id': '5e3c422f2e3f230d9a446b57', 'asset_type': 'JPG', 'media_type': 'image', 'filename': '049ec789_6557_41fa_83c1_8a1929822c74', 'object_id': '1933', 'object_type': 'episode', 'original_filename': 'moon2.jpg', 'asset_finals': [ { 'asset_type': 'JPG', 'asset_subtype': 'cover', 'filename': 'a.jpeg', 'url': 'http://url/a.jpeg', 'duration': 0 }, { 'asset_type': 'JPG', 'asset_subtype': 'large_cover', 'filename': 'b.jpeg', 'url': 'http://url/b.jpeg', 'duration': 0 }, { 'asset_type': 'JPG', 'asset_subtype': 'xlarge_cover', 'filename': 'c.jpeg', 'url': 'http://url/c.jpeg', 'duration': 0 }, { 'asset_type': 'TIF', 'asset_subtype': 'none', 'filename': 'd.tif', 'url': 'http://url/d.tif', 'duration': 0 } ], 'status': 'encoding_completed' } ])) @pytest.fixture def mock_megaphone(monkeypatch): """Set monkeypatched fixture for megaphone update.""" monkeypatch.setattr(megaphone, 'call_episode_api', MagicMock( return_value={'id': 1, 'uuid': 'b5f819ab-41b8-4104-90e9-1ceb751f55f8', 'uid': 'cowhouse'} )) @pytest.fixture def get_upload_permission_fixture(): """Return mocked upload credentials.""" return { 'bucket': 'some-bucket', 'filename': 'some-file.jpg', 'credentials': { 'token': 'a-token', 'aws_access_key_id': 'fake-key', 'aws_secret_access_key': 'fake-secret', 'expiration': '3600' } } @pytest.fixture def admin_user_fixture(): """Return create org admin user mocked payload.""" return { 'name': 'orgadmin', 'email': 'orgadmin@theorchard.com', 'role': 'admin', 'organization': 'orchard', 'all_networks': True } @pytest.fixture def network_user_fixture(): """Return create network admin user mocked payload.""" return { 'name': 'network-admin', 'email': 'network-admin@theorchard.com', 'network_ids': [1], 'role': 'network-admin', 'organization': 'orchard', 'all_networks': False } @pytest.fixture def user_fixture(): """Return create user mocked payload.""" return { 'name': 'First Last', 'email': ' email@theorchard.com ', 'uuid': '5da737d4d169330c5ad0f888', 'network_ids': [1], 'role': 'producer', 'organization': 'orchard', 'all_networks': False } @pytest.fixture def show_level_podcast_user_fixture(): """Return create show level podcast user mocked payload.""" return { 'name': 'Show Level Podcast Access', 'email': 'podcast_access@theorchard.com', 'podcast_ids': [1, 2], 'role': 'producer', 'organization': 'orchard', 'all_networks': False } @pytest.fixture def show_level_show_family_user_fixture(): """Return create show level show_family user mocked payload.""" return { 'name': 'Show Level ShowFamily Access', 'email': 'show_family_access@theorchard.com', 'show_family_ids': [3, 4], 'role': 'producer', 'organization': 'orchard', 'all_networks': False } @pytest.fixture def podcast_level_user_fixture(): """Return create user mocked payload.""" return { 'name': 'First Last', 'email': 'email1@theorchard.com', 'uuid': '5da737d4d169330c5ad0f888', 'podcast_ids': [1], 'role': 'producer', 'organization': 'orchard', 'all_networks': False } @pytest.fixture def oat_response_fixture(): """Return mock response for oat assets request.""" return {'items': [ { 'id': 3843, 'user_id': '5e2b54af7576f20de983c16a', 'asset_type': 'JPG', 'media_type': 'image', 'filename': 'e59e4fdb_f224_4285_a36b_87795e00e8a9', 'object_id': 1, 'object_type': 'episode', 'original_filename': 'Artwork.jpg', 'asset_finals': [ { 'asset_type': 'JPG', 'asset_subtype': 'cover', 'filename': 'images/cover/cover.jpeg', 'url': 'test-jpeg-url', 'duration': 0 }, { 'asset_type': 'JPG', 'asset_subtype': 'large_cover', 'filename': 'images/large_cover/large_cover.jpeg', 'url': 'test-jpeg-large-cover-url', 'duration': 0 }, { 'asset_type': 'JPG', 'asset_subtype': 'xlarge_cover', 'filename': 'images/xlarge_cover/xlarge_cover.jpeg', 'url': 'test-jpg-xlarge-cover-url', 'duration': 0 }, { 'asset_type': 'TIF', 'asset_subtype': 'none', 'filename': 'images/tif/51d56b1892dd4d85a38521a47073ceab_e59e4fdb_f224_4285_a36b_87795e00e8a9.tif', 'url': 'test-tif-url', 'duration': 0 } ], 'status': 'encoding_completed' }, { 'id': 3844, 'user_id': '5e2b54af7576f20de983c16a', 'asset_type': 'WAV', 'media_type': 'audio', 'filename': 'ab0b43d4_1d44_4264_842e_cb4a5e3af3ba', 'object_id': 1, 'object_type': 'episode', 'original_filename': "Tom's%20Show.wav", 'asset_finals': [ { 'asset_type': 'DAT', 'asset_subtype': 'none', 'filename': '385acdef_c508_4a62_8739_26596d5dd422.dat', 'url': 'test-dat-url', 'duration': 0 }, { 'asset_type': 'FLAC', 'asset_subtype': 'none', 'filename': 'bb7a6c85_a401_4354_a092_c361b9effa75.flac', 'url': 'test-flac-url', 'duration': 24384 }, { 'asset_type': 'MP3', 'asset_subtype': 'none', 'filename': '1c1a7df1_5291_40e3_817a_0976df33b824.mp3', 'url': 'test-mp3-url', 'duration': 24424 } ], 'status': 'encoding_completed' } ]} @pytest.fixture(autouse=True) def mock_signed_urls(monkeypatch): """Mock the signed_urls module.""" def mock_generate_presigned_url(self, url, date_less_than=None, policy=None): return '{}?Policy=policy&Signature=signature&Key-Pair-Id=key-pair'.format(url) monkeypatch.setattr(signed_urls, '_sign_url', MagicMock(side_effect=signed_urls._sign_url)) CloudFrontSigner.generate_presigned_url = mock_generate_presigned_url @pytest.fixture(autouse=True) def mock_email_sending(monkeypatch): """Mock sending emails.""" monkeypatch.setattr(email, '_send_sqs', MagicMock()) @pytest.fixture(autouse=True) def mock_boto(monkeypatch): """Mock sending emails.""" monkeypatch.setattr(boto3, 'client', MagicMock()) @pytest.fixture def podcast_title_fixture(): """Return podcast title.""" return 'test podcast title' @pytest.fixture def podcast_slug_fixture(): """Return podcast slug.""" return 'test-podcast' @pytest.fixture def invalid_podcast_slug_fixture(): """Return invalid podcast slug.""" return 'invalid-podcast' @pytest.fixture def store_url_fixture(): """Return store url.""" return 'https://test.com' @pytest.fixture def encoded_rss_fixture(): """Return encoded rss feed.""" return 'https%253A%252F%252Ffeeds%252Emegaphone%252Efm%252F' @pytest.fixture def stores_fixture(): """Return dictionary with store name as key and store id as value.""" return {store['id']: store['name'] for store in db_operations.stores} @pytest.fixture def apple_episodes_fixture(): """Return apple episodes.""" return { 'data': [ { 'id': '1', 'attributes': { 'name': 'title', 'assetUrl': 'https://test/mpuid.mp3', 'url': 'test-apple-episode-link' } }, { 'id': '2', 'attributes': { 'name': 'title2', 'assetUrl': 'https://test/mpuid2.mp3', 'url': 'test-apple-episode-link-2' } } ] } @pytest.fixture def apple_episodes_error_fixture(): """Return apple episodes error.""" return { 'errors': [ { 'title': 'No related resources', 'status': '404' } ] } @pytest.fixture def spotify_episodes_fixture_1(): """Return spotify episodes.""" return [ { 'name': db_operations.episode_data[0]['title'], 'description': 'description.', 'external_urls': { 'spotify': db_operations.episode_links[0]['link'] } } ] @pytest.fixture def spotify_episodes_fixture_2(): """Return spotify episodes.""" return [ { 'name': db_operations.episode_data[2]['title'], 'description': db_operations.episode_data[2]['description'], 'external_urls': { 'spotify': db_operations.episode_links[0]['link'] } } ] @pytest.fixture def stitcher_shows_fixture_1(): """Return stitcher shows.""" return { 'data': { 'shows': [ { 'title': 'alpha title 1', 'description': 'description 1. extraspaces with newlines.', 'slug': 'test-slug' } ] } } @pytest.fixture def stitcher_shows_fixture_2(): """Return stitcher shows.""" return { 'data': { 'shows': [ { 'title': 'incorrect title', 'description': 'incorrect description', 'slug': 'test-slug-2' } ] } } @pytest.fixture def stitcher_episodes_fixture(): """Return stitcher episodes.""" return { 'data': { 'shows': [ { 'title': 'title', 'description': 'description', 'link': 'test-link' } ], 'episodes': [ { 'id': 1, 'title': 'title', 'audio_url': 'https://test/mpuid.mp3', 'slug': 'random-episode-1' }, { 'id': 2, 'title': 'title-2', 'audio_url': 'https://test/mpuid2.mp3', 'slug': 'random-episode-2' }, { 'id': 3, 'title': 'title-3', 'audio_url': 'https://test/mpuid3.mp3', 'slug': 'random-episode-3' } ] }, 'orchestration': { 'page_size': 500, 'total_count': 3 } } @pytest.fixture def stitcher_episodes_error_fixture(): """Return stitcher error.""" return { 'errors': [ { 'error_id': '404', 'message': 'Unable to find show invalid-pod' } ] } @pytest.fixture def episode_links_data_fixture(): """Return episode links data.""" return {'items': [ { 'id': 1, 'store_id': 1, 'podcast_id': 1, 'episode_id': 1, 'link': 'first-link' }, { 'id': 2, 'store_id': 2, 'podcast_id': 1, 'episode_id': 1, 'link': 'second-link' } ]} @pytest.fixture def episode_link_fixture(): """Return episode link.""" return { 'store_id': 1, 'podcast_id': 1, 'episode_id': 3, 'link': 'link' } @pytest.fixture def rss_feed_episode_fixture(): """Return rss feed episode.""" return [ { 'title': 'title', 'guid': '6bf5bea4-a1d4-11e6-8dea-b334e2aa4880', 'episode_mp3_link': 'https://test/mpuid.mp3' } ] @pytest.fixture def player_fm_episodes_fixture(): """Return player fm episodes.""" return { 'episodes': [ { 'title': 'title', 'slug': 'test-1', 'url': 'https://test/mpuid.mp3' }, { 'title': 'title 2', 'slug': 'test-2', 'url': 'https://test/mpuid2.mp3' } ] } @pytest.fixture def org_invite_data_fixture(): """Return organization invite data.""" return { 'id': 'uinv_id', 'connection_id': 'con_id', 'client_id': 'abc', 'inviter': { 'name': 'Org admin' }, 'invitee': { 'email': 'test@theorchard.com' }, 'user_metadata': { 'orchardIdentityId': 'mock-uuid' }, 'invitation_url': 'https://test.com/?invitation=abc&organization=org_id&organization_name=org', 'ticket_id': 'ticket_id', 'created_at': '2021-06-14T18:25:22.203Z', 'expires_at': '2021-06-16T18:25:22.203Z', 'organization_id': 'org_qGYSq2K8lccfU1M5' } @pytest.fixture def episode_wav_asset_fixture(): """Return episode wav asset data.""" return { 'id': 1, 'user_id': '5e3c422f2e3f230d9a446b57', 'asset_type': 'WAV', 'media_type': 'audio', 'filename': '461f5444_a522_4ff1_b51f_17b699df621b', 'object_id': '1234', 'object_type': 'episode', 'original_filename': 'test.wav' } @pytest.fixture def podcast_artwork_asset_fixture(): """Return podcast artwork asset data.""" return { 'id': 2, 'user_id': 'a2f2f87f-1234-abcd-ecf2-1a89a51267c2', 'asset_type': 'JPG', 'filename': '39105918_39da_4fda_a7c4_6bbb0dc269ce', 'object_id': '1', 'object_type': 'podcast', 'created_date': '2024-01-02T10:39:08.000Z', 'updated_date': '2024-01-02T10:39:25.000Z', 'original_filename': 'test.jpg', 'media_type': 'image' } @pytest.fixture def mock_get_object_asset_by_id_and_type_wav(monkeypatch, episode_wav_asset_fixture): """Mock get object asset by id and type for episode wav asset.""" monkeypatch.setattr(oat, 'get_object_asset_by_id_and_type', MagicMock(return_value=episode_wav_asset_fixture)) @pytest.fixture def mock_get_object_asset_by_id_and_type_artwork(monkeypatch, podcast_artwork_asset_fixture): """Mock get object asset by id and type for podcast artwork asset.""" monkeypatch.setattr(oat, 'get_object_asset_by_id_and_type', MagicMock(return_value=podcast_artwork_asset_fixture)) @pytest.fixture def advertisement_fixture(): """Return fixture for advertisement by_order_ids.""" return { 'items': [ { 'campaign_order_megaphone_id': 'order_id', 'id': 'an-old-ad-id', 'insertion_point': 'pre' }, { 'campaign_order_megaphone_id': 'order_id', 'id': 'another-old-ad-id', 'insertion_point': 'pre' }, { 'campaign_order_megaphone_id': 'order_id', 'id': 'an-ad-id-pre', 'insertion_point': 'pre' } ] } @pytest.fixture def ad_actions_fixture(): """Return fixture for ad actions.""" return [ { 'id': 1, 'advertisement_id': 'an-old-ad-id', 'roll_type': 'pre', 'status': 'completed', 'due_date': '2021-08-10 22:00:00', 'created_date': '2021-08-01 22:00:00', }, { 'id': 2, 'advertisement_id': 'an-old-ad-id', 'roll_type': 'pre', 'status': 'completed', 'due_date': '2021-08-20 22:00:00', 'created_date': '2021-08-02 22:00:00' }, { 'id': 3, 'advertisement_id': 'an-old-ad-id', 'roll_type': 'pre', 'status': 'completed', 'due_date': '2021-08-30 22:00:00', 'created_date': '2021-08-03 22:00:00' } ] @pytest.fixture def ad_action_asset_fixture(): """Return fixture for asset from OAT for an ad action.""" return { 'items': [ { 'id': 7806, 'user_id': '1234', 'asset_type': 'WAV', 'filename': 'test', 'object_id': '1', 'object_type': 'adupload', 'original_filename': 'original_filename', 'media_type': 'audio', 'asset_finals': [ { 'asset_type': 'MP3', 'asset_subtype': 'none', 'filename': 'test.mp3', 'url': 'signed_url', 'duration': 1234 } ], 'status': 'encoding_completed' } ] } @pytest.fixture def megaphone_ads_fixture(): """Return fixture for megaphone advertisements.""" return [ { 'orderId': 'order_id', 'id': 'an-ad-id-pre', 'insertionPoint': 'pre' }, { 'orderId': 'order_id', 'id': 'an-ad-id-mid', 'insertionPoint': 'mid' } ] @pytest.fixture def player_daily_downloads_fixture(): """Return fixture for player daily downloads.""" return {'items': [ { 'player': 'Player1', 'report_date': '2020-09-04', 'downloads': 1158 }, { 'player': 'Player1', 'report_date': '2020-09-05', 'downloads': 874 }, { 'player': 'Player2', 'report_date': '2020-09-04', 'downloads': 100 }, { 'player': 'Player2', 'report_date': '2020-09-05', 'downloads': 200 } ]} @pytest.fixture def player_daily_downloads_data_fixture(): """Return fixture for request data for player daily downloads.""" return { 'object_id': 1, 'object_type': analytics_constants.NETWORK, 'date_range': analytics_constants.PAST_28_DAYS, 'countries': ['US', 'UK'], 'players': ['Player1', 'Player2'] } @pytest.fixture def pandora_data_fixture(): """Return fixture for pandora api data.""" return { 'searchToken': 'aafc6d0c-3ed6-4f91-bc4a-0b89d244fb05', 'annotations': { 'PE:9673056': { 'pandoraId': 'PE:9673056', 'name': 'test-podcast', 'shareableUrlPath': '/podcast/test-podcast/PE:9673056' }, 'PE:9673012': { 'pandoraId': 'PE:9673012', 'name': 'test-second-podcast', 'shareableUrlPath': '/podcast/test-second-podcast/PE:9673012' } } } @pytest.fixture def oat_episode_audio_assets_fixture(): """Return fixture oat asset replication data.""" return [ {'original_episode_id': 1, 'episode_id': 2, 'status': 'asset-replication-completed'} ] @pytest.fixture def replicate_single_episode_fixture(): """Return replicate single episode data.""" return { 'original_episode_id': 7, 'podcast_ids': [3, 4] } @pytest.fixture def replicate_single_episode_ad_locations_fixture(): """Return replicate single episode and ad locations data.""" return { 'original_episode_id': 7, 'podcast_ids': [1, 3], 'copy_ad_locations_podcast_ids': [1] } @pytest.fixture def update_episode_replication_status_fixture(): """Return update episode replication status data.""" return { 'ids': [1, 2, 3], 'show_family_id': 1 } @pytest.fixture def top_podcasts_fixture(): """Return top podcasts data.""" return { 'items': [ { 'podcast_id': 1, 'downloads': 2000 }, { 'podcast_id': 2, 'downloads': 1000 } ], 'pagination': { 'total_records': 2 } } @pytest.fixture def top_episodes_fixture(): """Return top episodes data.""" return { 'items': [ { 'episode_id': 1, 'podcast_id': 1, 'downloads': 2000 }, { 'episode_id': 2, 'podcast_id': 1, 'downloads': 1000 } ], 'pagination': { 'total_records': 2 } }