"""conftest.py. Test fixtures and configurations. """ import application from oto import response from oto.response import create_error_response from owslogger import flask_logger import pytest from sqlalchemy import exc from product_workflow.constants import header as header_constants @pytest.fixture def context(): """Return flask app context, including a mock logger. Returns: AppContext: flask app context, including a mock logger. """ class MockLog(): """Mock Logging Class.""" def error(self): pass def info(self): pass def warning(self): pass context = application.app.app_context() context.g.ows = flask_logger.Ows() context.g.ows.log = MockLog return context @pytest.fixture def client(): """Return flask test client.""" return application.app.test_client() @pytest.fixture def correlation_id(): """Provide a correlation_id for testing.""" return 'abc-123' @pytest.fixture def product_id(): """Provide a product_id for testing.""" return 123 @pytest.fixture def track_id(): """Provide a track_id for testing.""" return 123 @pytest.fixture def release_correction_id(): """Create a release correction id for testing.""" return 123 @pytest.fixture def valid_headers(correlation_id): """Generally-required headers for calls to this service. Returns: dict: header values. """ return { header_constants.CORRELATION_ID: correlation_id, header_constants.CONTENT_TYPE: 'application/json'} @pytest.fixture def valid_get_header(correlation_id): """Return valid GET request headers. Returns: (dict): header dict """ return { header_constants.CORRELATION_ID: correlation_id, header_constants.GRASS_ACCOUNT_TYPE: 'vendor', header_constants.GRASS_ACCOUNT_ID: '25257'} @pytest.fixture def db_exception(): """Return (but not throw) SQLAlchemy exception.""" return exc.SQLAlchemyError('kaboom') @pytest.fixture def release_approval_payload(): """Return a valid release approval payload.""" return { 'status': 'rejected', 'admin_approval': 'N'} @pytest.fixture def release_correction_payload(): """Return a valid release approval payload.""" return { 'last_updated_by': 12345, 'last_updated_type': 'vendor'} @pytest.fixture def release_correction_update_payload(): """Return a valid release approval payload.""" return { 'status': 'submitted', 'last_updated_by': 12345, 'last_updated_type': 'vendor'} @pytest.fixture def generic_error_response(): """Return a generic 400 level error response.""" return create_error_response( code='internal_error', message='something went wrong') @pytest.fixture def generic_error_payload(): """Return generic error payload for mocking services.""" return { 'message': 'Not found error message', 'code': 'not_found_error_code'} @pytest.fixture def get_ows_lyrics_message(track_id): """Response from ows_lyrics while applying correction lyrics.""" return { 'track_id': track_id, 'lyrics': 'Test Track lyrics' } @pytest.fixture def lyrics_correction_details(release_correction_id): """Return a list of the correction details properties for testing.""" return { 'release_correction_id': release_correction_id, 'table_name': 'track', 'field_name': 'lyrics', 'key_id': 124, 'key_value': 'Test Track lyrics', } @pytest.fixture def get_tracks_by_product_id_response(product_id): """Return a tracks data.""" return { 'items': [ { 'localizations': [], 'version': '', 'upc': 1234, 'p_info': '2019 P info', 'track_number': 1, 'tuid': 1, 'track_name': 'Test Track 1', 'volume_number': 1, 'explicit': 'N', 'recording_country_id': 16, 'meta_language_code': 'ENG', 'product_id': product_id, 'original_rights_holder_country_id': 16, 'ownership_rights': 'original_owner', 'preview_start_time': None, 'isrc': '1234', 'artists': [ { 'name': 'Test', 'track_artist_id': 1234, 'type': 'performer' } ], 'writers': [ { 'name': 'Test', 'type': 'writer', 'track_writer_id': 1234 } ] }, { 'localizations': [], 'version': '', 'upc': 1234, 'p_info': '2019 P info', 'track_number': 2, 'tuid': 2, 'track_name': 'Test Track 2', 'volume_number': 1, 'explicit': 'N', 'recording_country_id': 16, 'meta_language_code': 'ENG', 'product_id': product_id, 'original_rights_holder_country_id': 16, 'ownership_rights': 'original_owner', 'preview_start_time': None, 'isrc': '1234', 'artists': [ { 'name': 'Test', 'track_artist_id': 1234, 'type': 'performer' } ], 'writers': [ { 'name': 'Test', 'type': 'writer', 'track_writer_id': 1234 } ] }, { 'localizations': [], 'version': '', 'upc': 1234, 'p_info': '2019 P info', 'track_number': 3, 'tuid': 3, 'track_name': 'Test Track 3', 'volume_number': 1, 'explicit': 'N', 'recording_country_id': 16, 'meta_language_code': 'ENG', 'product_id': product_id, 'original_rights_holder_country_id': 16, 'ownership_rights': 'original_owner', 'preview_start_time': None, 'isrc': '1234', 'artists': [ { 'name': 'Test', 'track_artist_id': 1234, 'type': 'performer' } ], 'writers': [ { 'name': 'Test', 'type': 'writer', 'track_writer_id': 1234 } ] } ], 'pagination': {'total_records': 2, 'type': 'none'} } @pytest.fixture def get_tracks_by_product_id_no_tracks_response(): """Return a response data with no tracks.""" return { 'items': [], 'pagination': { 'total_records': 0, 'type': 'none' } } @pytest.fixture def get_lyrics_by_track_ids_response(): """Return lyrics data.""" return { 'items': [ {'track_id': 2, 'lyrics': 'Test Tracks Lyrics'} ] } @pytest.fixture def get_lyrics_by_track_ids_not_found_response(): """Return not found response.""" return create_error_response( code='not_found_error', message='null', status=404) @pytest.fixture def get_lyrics_by_product_id_response(): """Return lyrics response for the product.""" return { 'tracks': [ { 'track_id': 1, 'has_lyrics': True, 'lyrics_corrected': True }, { 'track_id': 2, 'has_lyrics': True, 'lyrics_corrected': False }, { 'track_id': 3, 'has_lyrics': False, 'lyrics_corrected': False } ] } @pytest.fixture def get_lyrics_by_product_id_not_found_response(): """Return lyrics response for the product.""" return { 'code': 'not_found_error', 'message': 'No lyrics data found for the product' } @pytest.fixture def get_lyrics_by_track_ids_message(): """Response from ows_lyrics while applying correction correction lyrics.""" return [ { 'track_id': 1, 'lyrics': 'Lyrics Test 1' }, { 'track_id': 2, 'lyrics': 'Lyrics Test 2' } ] @pytest.fixture def get_last_release_correction_response_for_lyrics(release_correction_id): """Return correction response for lyrics correction details.""" return response.Response({ 'release_correction_id': release_correction_id, 'status': 'submitted', 'items': [ { 'release_correction_detail_id': 123, 'table_name': 'track', 'field_name': 'lyrics', 'key_id': 1, 'key_value': 'Lyrics Text' } ] }) @pytest.fixture def get_lyrics_in_correction_not_found_response(): """Return correction response for lyrics correction details.""" return response.create_not_found_response( message='No lyrics correction record found') @pytest.fixture def get_lyrics_in_correction_response(release_correction_id, product_id): """Return a dictionary of last release correction properties.""" return [ { 'release_correction_detail_id': 123, 'table_name': 'track', 'field_name': 'lyrics', 'key_id': 1, 'key_value': 'Lyrics Text' } ] @pytest.fixture def get_lyrics_by_track_id_response(track_id): """Return lyrics response for the track.""" return { 'track_id': track_id, 'lyrics': 'Lyrics Text' } @pytest.fixture def get_lyrics_by_track_ids_response_for_single_track(track_id): """Return lyrics data.""" return { 'items': [ {'track_id': track_id, 'lyrics': 'Lyrics Text'} ] } @pytest.fixture def get_lyrics_by_track_id_not_found_response(): """Return lyrics response for the track.""" return { 'code': 'not_found_error', 'message': 'No lyrics data found for the track' } @pytest.fixture def get_lyrics_in_correction_for_single_track_response( release_correction_id, product_id, track_id): """Return a dictionary of last release correction properties.""" return { 'release_correction_detail_id': 123, 'table_name': 'track', 'field_name': 'lyrics', 'key_id': track_id, 'key_value': 'Lyrics Text' } @pytest.fixture def account_id(): """Return an account id.""" return 1234 @pytest.fixture def account_type(): """Return an account type.""" return 'vendor'