"""conftest. This file gets picked up when running py.test tests: http://pytest.org/latest/writing_plugins.html#conftest """ import application from owslogger import flask_logger import pytest from artist.constants import account from artist.constants import headers as headers_constants from artist.models.artist import Artist from artist.models.release_artist import ReleaseArtist from artist.models.track import Track from artist.models.track_artist import TrackArtist from artist.models.track_writer import TrackWriter @pytest.fixture def account_id(): """Fake account id for testing.""" return 12345 @pytest.fixture def artist_id(): """Test artist_id.""" return 123 @pytest.fixture def artist_name(): """Test artist_name.""" return 'Test Artist' @pytest.fixture def vendor_id() -> int: """Test vendor_id.""" return 1234 @pytest.fixture def subaccount_id() -> int: """Test subaccount_id.""" return 5678 @pytest.fixture def isni_id(): """Test isni_id.""" return 'test123' @pytest.fixture def identifier_data(): """Test data of artist_identifier.""" return {'store_id': '1', 'identifier': '123'} @pytest.fixture def client(): """Return flask test client. Returns: flask client: flask test client """ return application.app.test_client() @pytest.fixture def headers(): """Return valid headers with content type and correlation id. Returns: dict: header dict """ return { headers_constants.CORRELATION_ID: 'abc-123', headers_constants.CONTENT_TYPE: 'application/json'} @pytest.fixture def valid_headers_for_vendor(headers, account_id): """Return valid headers with vendor type and account id. Returns: dict: header dict """ headers.update({ headers_constants.GRASS_ACCOUNT_TYPE: account.VENDOR_TYPE, headers_constants.GRASS_ACCOUNT_ID: account_id}) return headers @pytest.fixture def valid_headers_for_subaccount(headers, account_id): """Return valid headers with subaccount type and account id. Returns: dict: header dict """ headers.update({ headers_constants.GRASS_ACCOUNT_TYPE: account.SUBACCOUNT_TYPE, headers_constants.GRASS_ACCOUNT_ID: account_id}) return headers @pytest.fixture def valid_headers_for_oa(headers, account_id): """Return valid headers with oa type and account id. Returns: dict: header dict """ headers.update({ headers_constants.ORCHARD_USER_ID: f'{account.OA_TYPE}:{account_id}' }) return headers @pytest.fixture def release_id(): """Fixture for release id.""" return 1337 @pytest.fixture def artist_infos(): """Fixture for artist info objects.""" return [ Artist( artist_id=5, artist_type='artist' ), Artist( artist_id=6, artist_type='tv_artist' ), Artist( artist_id=7, artist_type='film_collection' ), Artist( artist_id=8, artist_type='artist' ), Artist( artist_id=9, artist_type='tv_artist' ) ] @pytest.fixture def artist_infos_with_isnis(): """Fixture for artist info objects with isni ids.""" return [ Artist( artist_id=5, artist_type='artist', isni_id='what is this?' ), Artist( artist_id=6, artist_type='tv_artist', isni_id='not all of us have one' ), Artist( artist_id=7, artist_type='film_collection' ), Artist( artist_id=8, artist_type='tv_artist' ), Artist( artist_id=9, artist_type='film_collection', isni_id='phew just made it' ) ] @pytest.fixture def release_artists(artist_infos, release_id): """Fixture for release artists.""" return [ ReleaseArtist( release_id=release_id, artist_name='First artist', role='First role', artist_info_id=artist_infos[0].artist_id ), ReleaseArtist( release_id=release_id, artist_name='Second artist', role='Second role', artist_info_id=artist_infos[1].artist_id ) ] @pytest.fixture def tracks(release_id): """Fixture for tracks.""" return [ Track(id=index, release_id=release_id) for index in range(1, 6) ] @pytest.fixture def track_artists(artist_infos, tracks): """Fixture for track artists.""" return [ TrackArtist( artist_info_id=artist_infos[0].artist_id + index, artist_name='First track artist', role='First track role', track_id=track.id, ) for index, track in enumerate(tracks) ] @pytest.fixture def track_writers(artist_infos, tracks): """Fixture for track writers.""" return [ TrackWriter( artist_info_id=artist_infos[0].artist_id + index, writer_name='First track writer', unique_track_id=track.id, ) for index, track in enumerate(tracks) ] @pytest.fixture def app_context(): """Yield app context.""" with application.app.app_context(): yield @pytest.fixture def context(): """Return flask app context, including a mock logger. Returns: AppContext: flask app context, including a mock logger. """ class MockLog(): 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 artist_data(): """Return artist data.""" return [ { 'id': 853004, 'artist_type': 'artist', 'name': 'Ben Rubin', 'isni_id': None, 'vendor_id': 25824, 'store_id': 4, 'identifier': 'identifier1' }, { 'id': 853004, 'artist_type': 'film_collection', 'name': 'Ben Rubin', 'isni_id': None, 'vendor_id': 25824, 'store_id': 12, 'identifier': 'identifier2' } ] @pytest.fixture def artist_object(): """Fixure of update_artist result.""" return Artist( artist_id=5, vendor_id=123, artist_type='tv_artist', isni_id='what is this?', name='Test Artist' ) @pytest.fixture def update_artist_result(): """Fixure of update_artist result.""" return { 'id': 1, 'artist_type': 'artist', 'name': 'Test Artist' } @pytest.fixture def artist_update_data(): """Fixture for request data for update_artist.""" return {'isni_id': 'test12334', 'vendor_id': 12345, 'artist_identifier': [ {'store_id': '1', 'identifier': 'popular'}, {'store_id': '2', 'identifier': 'whope'} ] } @pytest.fixture def artist_identifer_data(): """Fixture of artist_identifier array.""" return { 'store_id': '1', 'identifier': 'popular' }