"""Tests for analytics handlers.""" from unittest.mock import MagicMock, patch from oto import status from podcast.constants import analytics as analytics_constants from podcast.logic import analytics def test_country_daily_downloads(fixture_client, monkeypatch): """Test get country daily downloads handler.""" monkeypatch.setattr( analytics, 'country_daily_downloads', MagicMock( return_value={'items': [{'country': 'US', 'downloads': 300, 'report_date': '2021-02-02'}]})) params = { 'object_id': '1', 'object_type': analytics_constants.NETWORK, 'date_range': analytics_constants.ALL_TIME, 'countries': 'US,CA', 'players': [] } result = fixture_client.get('/country-daily-downloads', query_string=params) assert result.status_code == status.OK assert len(result.json['items']) == 1 @patch('podcast.logic.analytics.player_daily_downloads') def test_player_daily_downloads_handler( mock_player_daily_downloads, fixture_client, player_daily_downloads_data_fixture): """Test player daily downloads handler.""" data = {'items': player_daily_downloads_data_fixture} mock_player_daily_downloads.return_value = data handler_url = 'player-daily-downloads?date_range=past_year&object_id=33&object_type=network&players=Apple' result = fixture_client.get(handler_url, data=data) assert result.status_code == status.OK