"""Tests for ows_track model.""" import pytest from models import ows_track import const # noqa import index # noqa def test_get_track_artist_info( mocker, track_id, track_info_success_response, artist_name, get_track_info_fixture): """Test get track info from ows-track successfully.""" mocker.patch( 'requests.get', return_value=track_info_success_response) result = ows_track.get_track_artist_info(track_id) assert result == get_track_info_fixture def test_get_track_info_not_found( mocker, ows_not_found_response, track_id, get_track_info_not_found_fixture): """Test get track info from ows-track not found.""" mocker.patch( 'requests.get', return_value=ows_not_found_response) result = ows_track.get_track_artist_info(track_id) assert result == get_track_info_not_found_fixture def test_get_track_info_error(mocker, ows_error_response, track_id): """Test get track info from ows-track error.""" mocker.patch( 'requests.get', return_value=ows_error_response) with pytest.raises(Exception, match=const.OWS_TRACK_ERROR): ows_track.get_track_artist_info(track_id) def test_get_track_info_retry_on_error(mocker, ows_error_response, track_id): """Test get track info with 2 retries.""" request = mocker.patch('requests.get', return_value=ows_error_response) try: ows_track.get_track_artist_info(track_id) except Exception as error: assert len(request.mock_calls) == 2 assert str(error) == const.OWS_TRACK_ERROR def test_get_all_tracks_by_product_id( mocker, release_id, tracks_by_product_id_success_response, get_tracks_by_product_id_fixture): """Test get tracks from product id from ows-track successfully.""" mocker.patch( 'requests.get', return_value=tracks_by_product_id_success_response) result = ows_track.get_all_tracks_by_product_id(release_id) assert len(result) == 2 assert result == get_tracks_by_product_id_fixture def test_get_all_tracks_not_found(mocker, ows_not_found_response, release_id): """Test get tracks from product id from ows-track not found.""" mocker.patch( 'requests.get', return_value=ows_not_found_response) result = ows_track.get_all_tracks_by_product_id(release_id) assert result == [] def test_get_all_tracks_error(mocker, ows_error_response, release_id): """Test get tracks from product id from ows-track error.""" mocker.patch( 'requests.get', return_value=ows_error_response) with pytest.raises(Exception, match=const.OWS_TRACK_ERROR): ows_track.get_all_tracks_by_product_id(release_id) def test_get_all_tracks_retry_on_error(mocker, ows_error_response, release_id): """Test get tracks from product id with 2 retries.""" request = mocker.patch('requests.get', return_value=ows_error_response) try: ows_track.get_all_tracks_by_product_id(release_id) except Exception as error: assert len(request.mock_calls) == 2 assert str(error) == const.OWS_TRACK_ERROR