"""Test for update episode description.""" from unittest.mock import MagicMock, patch from scripts import update_episode_description from scripts.update_episode_description import update_db_and_megaphone from scripts.update_episode_description import update_megaphone from podcast.logic import megaphone from tests.utils import db_operations bad_string = '
Learn more about your ad choices.
' mock_podcast = db_operations.podcast_data[0] mock_updated_description = {'description': 'description3
'} def test_get_podcast_episodes(monkeypatch, episode_bad_description_fixture): """Get episodes having bad string in description.""" monkeypatch.setattr( update_episode_description, 'get_podcast_episodes', MagicMock( return_value=[episode_bad_description_fixture])) episodes = update_episode_description.get_podcast_episodes(1, True) assert len(episodes) == 1 assert bad_string in episodes[0]['description'] def test_update_megaphone(mock_megaphone, episode_bad_description_fixture): """Test update episode details in megaphone.""" episode_bad_description_fixture['description'] = 'description3
' update_megaphone( mock_podcast, episode_bad_description_fixture ) megaphone.call_episode_api.assert_called_with( { 'summary': 'description3
', 'retainAdLocations': True }, '6bf5bea4-a1d4-11e6-8dea-b334e2aa4710', '6bf5bea4-a1d4-11e6-8dea-b334e2aa4811', 1, episode_bad_description_fixture['id'] ) @patch('scripts.update_episode_description.update_megaphone') @patch('podcast.models.episode.update_episode') def test_update_db_and_megaphone(mock_update_db, mock_update_megaphone, episode_bad_description_fixture): """Test update database and megaphone called.""" is_update_in_megaphone = True update_db_and_megaphone([episode_bad_description_fixture], mock_podcast, bad_string, is_update_in_megaphone) mock_update_db.assert_called_once_with(4, mock_updated_description) mock_update_megaphone.assert_called() @patch('scripts.update_episode_description.update_megaphone') @patch('podcast.models.episode.update_episode') def test_update_db_and_not_megaphone(mock_update_db, mock_update_megaphone, episode_bad_description_fixture): """Test update database and megaphone not called.""" is_update_in_megaphone = False update_db_and_megaphone([episode_bad_description_fixture], mock_podcast, bad_string, is_update_in_megaphone) mock_update_db.assert_called_once_with(4, mock_updated_description) mock_update_megaphone.assert_not_called()