"""Unit tests for Track logic.""" from unittest.mock import MagicMock from owsrequest import request as requests from owsrequest import test_utils from promo_player.constants import service_name from promo_player.logic import product from promo_player.logic import track def test_is_owner(monkeypatch, fixture_success): """Test checking ownership of a track.""" account_type = 'vendor' account_id = '123' track_id = 456 json_response_mock = { 'product_id': 789 } path = '/track/{track_id}'.format(track_id=track_id) call_specs = [{ 'service': service_name.OWS_TRACK, 'path': path, 'status': 200, 'json': json_response_mock }] monkeypatch.setattr( requests, 'get', test_utils.mock_ows_requests(call_specs)) monkeypatch.setattr( product, 'is_owner', MagicMock(return_value=fixture_success)) response = track.is_owner(track_id, account_type, account_id) assert response assert response.status == fixture_success.status def test_is_owner_track_not_found(monkeypatch): """Test that an error response is returned if no track response.""" account_type = 'vendor' account_id = '123' track_id = 456 path = '/track/{track_id}'.format(track_id=track_id) call_specs = [{ 'service': service_name.OWS_TRACK, 'path': path, 'status': 404 }] monkeypatch.setattr( requests, 'get', test_utils.mock_ows_requests(call_specs)) response = track.is_owner(track_id, account_type, account_id) assert not response assert response.status == 404