"""Unit tests for Episode Link model.""" from oto import status import pytest from podcast.models import episode_links from podcast.utils.exc import OwsError def test_get_episode_links(): """Test get episode link model return data by podcast id.""" podcast_id = 2 result = episode_links.get_episode_links(podcast_id) assert result['items'] == [ {'id': 1, 'store_id': 2, 'podcast_id': 2, 'episode_id': 3, 'link': 'https://www.spotify.com/xyz/episode/123'} ] def test_get_episode_links_not_found(): """Test episode link model if podcast id doesn't exist.""" podcast_id = 999 result = episode_links.get_episode_links(podcast_id) assert result['items'] == [] def test_get_episode_links_by_episode_id(): """Test get episode link model return data by episode id.""" episode_id = 3 result = episode_links.get_episode_links_by_episode_id(episode_id) assert result['items'] == [ {'id': 1, 'store_id': 2, 'podcast_id': 2, 'episode_id': 3, 'link': 'https://www.spotify.com/xyz/episode/123'} ] def test_get_episode_links_by_episode_id_not_found(): """Test episode link model if episode id doesn't exist.""" episode_id = 999 result = episode_links.get_episode_links_by_episode_id(episode_id) assert result['items'] == [] def test_create_or_update_episode_link(episode_link_fixture): """Test create or update_episode link.""" result = episode_links.create_or_update_episode_link(episode_link_fixture) assert result == {'id': 3, 'store_id': 1, 'podcast_id': 1, 'episode_id': 3, 'link': 'link'} episode_link_fixture['link'] = 'test-link' result = episode_links.create_or_update_episode_link(episode_link_fixture) assert result == {'id': 3, 'store_id': 1, 'podcast_id': 1, 'episode_id': 3, 'link': 'test-link'} def test_delete_episode_link(): """Test delete episode link.""" episode_id = 3 store_id = 2 result = episode_links.delete_episode_link(episode_id, store_id) assert result is None def test_delete_episode_link_not_found(): """Test delete episode link if episode link doesn't exist.""" episode_id = 99 store_id = 99 with pytest.raises(OwsError) as err: episode_links.delete_episode_link(episode_id, store_id) assert err.value.status == status.NOT_FOUND