"""Tests for bootstrap utils of Proper Changed Releases flow.""" import os from unittest.mock import patch from feed_sender.flows import helpers from feed_sender.flows.proper_changed_releases import config from feed_sender.flows.proper_changed_releases.util import bootstrap 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._get_destination_s3_path(context_date) assert resp == ( 's3://{}-feed-sender/proper/outgoing/2016-01-01/changed/' 'essential_changes_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._get_destination_sftp_path(context_date) assert resp == ( '{remote_sftp_path}' 'essential_changes_2016_01_01.csv').format( remote_sftp_path=config.SFTP_REMOTE_PATH) @patch( 'feed_sender.flows.proper_changed_releases.util.bootstrap.' 's3LocalUtils') @patch( 'feed_sender.flows.proper_changed_releases.util.bootstrap.' '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.feed_already_sent('test_feed', '2016-03-04', True) assert resp @patch( 'feed_sender.flows.proper_changed_releases.util.bootstrap.' 's3LocalUtils') @patch( 'feed_sender.flows.proper_changed_releases.util.bootstrap.' '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.feed_already_sent('test_feed', '2016-03-04', True) assert not resp @patch( 'feed_sender.flows.proper_changed_releases.util.bootstrap.' 's3LocalUtils') @patch( 'feed_sender.flows.proper_changed_releases.util.bootstrap.' '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.feed_already_sent('test_feed', '2016-03-04', True) assert not resp