"""Shared test mocks.""" import json import pytest def load_file(filepath): """Load file.""" with open(filepath) as event_file: return event_file.read() def load_file_json(filepath): """Load json from file.""" return json.loads(load_file(filepath)) @pytest.fixture def mock_event(): """Mock event.""" return load_file_json('tests/sample_event.json') @pytest.fixture def mock_row_data(): """Mock row data.""" return { 'id': 1, 'product_id': 1, 'status': 'new', 'created_datetime': '2021-08-03T01:13:14Z' } @pytest.fixture def mock_graphql_response(): """Mock graphql response for a label's product.""" return { 'data': { 'product': { 'artists': [ { 'artistId': '7222718', 'artistName': 'Sinaloha', 'artistType': 'primary_artist' }, { 'artistId': '7222720', 'artistName': 'PRONOUN', 'artistType': 'featuring' }, { 'artistId': '7222721', 'artistName': 'PeterPeter', 'artistType': 'remixer' }, { 'artistId': '7222722', 'artistName': 'CCubed', 'artistType': 'producer' } ], 'cLine': '2021 petertest', 'productConfiguration': 'Digital Audio', 'deliveredVersion': 'For Ui', 'format': 'Full Length', 'label': { 'name': 'Non-Mechanical M/USD', 'id': { 'subaccountId': 0, 'vendorId': 16160 } }, 'imageLocation': 'http://image.png', 'imprint': 'petertest', 'metadataLanguage': { 'name': 'English', 'code': 'ENG' }, 'productCode': 'CONTEST02', 'productId': 1, 'productName': 'Contest02', 'preorderDate': None, 'releaseDate': '2022-07-01', 'saleStartDate': '2022-07-01', 'specialInstructions': 'SI', 'subgenre': { 'id': 662, 'genre': { 'id': 20, 'name': 'Blues' } }, 'upc': '196292189827', 'displayUpc': '196292189827', 'version': 'Content Review UI Testing', 'reviewHistory': { 'totalCount': 0, 'items': [] } } } } @pytest.fixture def mock_index_document(mock_row_data, mock_graphql_response): """Mock an indexed product document.""" product_metadata = mock_graphql_response.get('data').get('product') return { 'added_at': mock_row_data.get('created_datetime'), 'display_upc': product_metadata.get('displayUpc'), 'review_queue_id': mock_row_data.get('id'), 'featuring_artist': 'Artist2', 'format': product_metadata.get('format'), 'image_location': product_metadata.get('imageLocation'), 'imprint': product_metadata.get('imprint'), 'label_id': product_metadata.get('label').get('id').get('vendorId'), 'label_name': 'Label1', 'preorder_date': product_metadata.get('preorderDate'), 'primary_artist': 'Artist1', 'product_id': mock_row_data.get('product_id'), 'product_name': product_metadata.get('productName'), 'sale_start_date': product_metadata.get('saleStartDate'), 'special_instructions': product_metadata.get('specialInstructions'), 'upc': product_metadata.get('upc'), 'subaccount_id': product_metadata.get('label').get('id').get( 'subaccountId'), 'subaccount_name': '', }