"""Test for the stats model.""" from unittest.mock import patch from socials.models import stats as stats_model def test_get_stats(): """Test get_timeseries.""" stats_mock_response = (37353950, 98, 33305611) with patch.object( stats_model.snowflake, 'fetchone', return_value=stats_mock_response ): response = stats_model.get_stats(206557) assert response == { 'followers': 37353950, 'popularity': 98, 'monthlyListeners': 33305611, } def test_get_stats_empty(): """Test get_timeseries.""" stats_empty_response = None with patch.object( stats_model.snowflake, 'fetchone', return_value=stats_empty_response ): response = stats_model.get_stats(20655700000) assert response == {} def test_get_stats_by_account(): """Test get_timeseries.""" account_stats_mock_response = [ ('spotify', 'https://spotify-bla-bla-bla', 222222, 12, 3333, 0.85), ('apple', 'https://apple-bla-bla-bla', 11111, 44, 5555, None), ] with patch.object( stats_model.snowflake, 'fetchall', return_value=account_stats_mock_response ): response = stats_model.get_stats_by_account(206557, None) assert response == [ { 'platform': 'spotify', 'url': 'https://spotify-bla-bla-bla', 'followers': 222222, 'popularity': 12, 'monthlyListeners': 3333, 'fanConversionPercentage': 0.85 }, { 'platform': 'apple', 'url': 'https://apple-bla-bla-bla', 'followers': 11111, 'popularity': 44, 'monthlyListeners': 5555, 'fanConversionPercentage': None }, ] def test_get_stats_by_account_empty(): """Test get_timeseries.""" account_stats_empty_response = [] with patch.object( stats_model.snowflake, 'fetchall', return_value=account_stats_empty_response ): response = stats_model.get_stats_by_account(206557, None) assert response == [] def test_get_stats_by_account_url(): """Test get_timeseries.""" account_url = 'https://spotify-bla-bla-bla' account_stats_mock_response = ('spotify', account_url, 222222, 12, 3333) with patch.object( stats_model.snowflake, 'fetchone', return_value=account_stats_mock_response ): response = stats_model.get_stats_by_account_url(account_url) assert response == { 'platform': 'spotify', 'url': 'https://spotify-bla-bla-bla', 'followers': 222222, 'popularity': 12, 'monthlyListeners': 3333, } def test_get_stats_by_account_url_empty(): """Test get_timeseries.""" account_url = 'https://spotify-bla-bla-bla' account_stats_empty_response = None with patch.object( stats_model.snowflake, 'fetchone', return_value=account_stats_empty_response ): response = stats_model.get_stats_by_account_url(account_url) assert response == {} def test_get_stats_by_artists_ids(): "Test get stats for multiple artists." artists_stats_mock_response = [ (415788, 424242, 22011919, 200000, 100000, 150000, 200, None, 30000, 40000), (848189, 24081991, None, 5555, 123123, 34541, 4366, 2123, 32445, None), ] with patch.object( stats_model.snowflake, 'fetchall', return_value=artists_stats_mock_response ): response = stats_model.get_stats_by_artists_ids([415788, 848189]) assert response == [ { 'chartmetricArtistId': 415788, 'spotifyMonthlyListeners': 424242, 'instagramFollowers': 22011919, 'tiktokFollowers': 200000, 'spotifyFollowers': 100000, 'facebookFollowers': 150000, 'youtubeFollowers': 200, 'twitterFollowers': None, 'soundcloudFollowers': 30000, 'deezerFollowers': 40000, }, { 'chartmetricArtistId': 848189, 'spotifyMonthlyListeners': 24081991, 'instagramFollowers': None, 'tiktokFollowers': 5555, 'spotifyFollowers': 123123, 'facebookFollowers': 34541, 'youtubeFollowers': 4366, 'twitterFollowers': 2123, 'soundcloudFollowers': 32445, 'deezerFollowers': None, }, ]