"""Tests for bootstrap utils of Proper New Releases Tracks flow.""" import os from unittest.mock import patch from feed_sender.flows import helpers from feed_sender.flows.proper_new_releases_tracks.conf import settings from feed_sender.flows.proper_new_releases_tracks.util import bootstrap_util def test_get_destination_s3_path(): """Test _get_destination_s3_path. Note that path will be gotten from config file once it is available. """ context_date = '2016-01-01' env = os.getenv('Environment') resp = bootstrap_util._get_destination_s3_path(True, context_date) assert resp == ( 's3://{}-feed-sender/proper/outgoing/2016-01-01/new/' 'essential_setups_tracklistings_2016_01_01.csv').format(env) resp = bootstrap_util._get_destination_s3_path(False, context_date) assert resp == ( 's3://{}-feed-sender/proper/outgoing/2016-01-01/new/' 'essential_setups_2016_01_01.csv').format(env) def test_get_destination_sftp_path(): """Test _get_destination_sftp_path. Path is subjected to change, according to the settings.py file. """ context_date = '2016-01-01' resp = bootstrap_util._get_destination_sftp_path(True, context_date) assert resp == ( '{ftp_path}essential_setups_tracklistings_2016_01_01.csv').format( ftp_path=settings.SFTP_REMOTE_PATH) resp = bootstrap_util._get_destination_sftp_path(False, context_date) assert resp == '{ftp_path}essential_setups_2016_01_01.csv'.format( ftp_path=settings.SFTP_REMOTE_PATH) @patch( 'feed_sender.flows.proper_new_releases_tracks.util.bootstrap_util.' 's3LocalUtils') @patch( 'feed_sender.flows.proper_new_releases_tracks.util.bootstrap_util.' 'helpers') def test_feed_already_sent(mock_helpers, mock_s3LocalUtils): """Test feed_already_sent.""" mock_s3LocalUtils.check_s3_key_exist.return_value = True mock_helpers.STATUS_SENT = helpers.STATUS_SENT mock_helpers.get_status.return_value = helpers.STATUS_SENT resp = bootstrap_util.feed_already_sent('test_feed', '2016-03-04', True) assert resp @patch( 'feed_sender.flows.proper_new_releases_tracks.util.bootstrap_util.' 's3LocalUtils') @patch( 'feed_sender.flows.proper_new_releases_tracks.util.bootstrap_util.' 'helpers') def test_feed_not_sent(mock_helpers, mock_s3LocalUtils): """Test feed_already_sent.""" mock_s3LocalUtils.check_s3_key_exist.return_value = False mock_helpers.STATUS_SENT = helpers.STATUS_SENT mock_helpers.get_status.return_value = helpers.STATUS_SENT resp = bootstrap_util.feed_already_sent('test_feed', '2016-03-04', True) assert not resp @patch( 'feed_sender.flows.proper_new_releases_tracks.util.bootstrap_util.' 's3LocalUtils') @patch( 'feed_sender.flows.proper_new_releases_tracks.util.bootstrap_util.' 'helpers') def test_feed_is_processing(mock_helpers, mock_s3LocalUtils): """Test feed_already_sent.""" mock_s3LocalUtils.check_s3_key_exist.return_value = True mock_helpers.STATUS_SENT = helpers.STATUS_SENT mock_helpers.get_status.return_value = helpers.STATUS_PROCESSING resp = bootstrap_util.feed_already_sent('test_feed', '2016-03-04', True) assert not resp