"""Tests for IngestionFeed module and class methods.""" from collections import OrderedDict import datetime from unittest.mock import patch import freezegun from feed_status.models import feed_monitor from feed_status.models import ingestion_feed mock_ingestion_feed_config = [ ingestion_feed.IngestionFeed( feed_id=11, feed_name='24/7', status_source_db='feed_status', update_freq=1, feed_type=ingestion_feed.INGESTION_TYPE_DAILY), ingestion_feed.IngestionFeed( feed_id='Apple Music', feed_name='Apple Music', status_source_db='feed_status', update_freq=1, feed_type=ingestion_feed.INGESTION_TYPE_DAILY) ] class TestGetIngestionFeedById: """Unit tests for get_feed_by_id().""" @patch('feed_status.models.ingestion_feed.active_feeds', mock_ingestion_feed_config) def test_find_by_feed_id_int(self): """Test we can find IngestionFeeds by feed_id.""" feed = feed_monitor.get_feed_by_id(11) assert type(feed) is ingestion_feed.IngestionFeed @patch('feed_status.models.ingestion_feed.active_feeds', mock_ingestion_feed_config) def test_find_by_feed_id_str(self): """Test we can find IngestionFeeds by feed_id.""" feed = feed_monitor.get_feed_by_id('Apple Music') assert type(feed) is ingestion_feed.IngestionFeed @freezegun.freeze_time(datetime.date(2022, 8, 1)) @patch.object( ingestion_feed.feed_status, 'get_ingestion_history', return_value=[]) def test_get_feed_ingestion_history(feed_status_mock): """Test get_feed_ingestion_history.""" to_date = datetime.datetime.now().date() from_date = to_date - datetime.timedelta(days=10) result = ingestion_feed.get_feed_ingestion_history( feed=ingestion_feed.active_feeds[0], from_date=from_date, to_date=to_date ) assert result == OrderedDict([ ('2022-08-01', '--'), ('2022-07-31', '--'), ('2022-07-30', '--'), ('2022-07-29', '--'), ('2022-07-28', '--'), ('2022-07-27', '--'), ('2022-07-26', '--'), ('2022-07-25', '--'), ('2022-07-24', '--'), ('2022-07-23', '--'), ])