"""Unit tests for the fetch_country_groups tasks.""" from unittest.mock import patch from activity_detector import base_config from activity_detector.flows.trending_tracks.tasks.\ fetch_country_groups import fetch_country_groups def test_fetch_country_groups(mock_snowflake): """Test fetching trending tracks country groups.""" with patch('activity_detector.flows.trending_tracks.tasks' '.fetch_country_groups.sql_loader') \ as mock_loader: mock_loader.load_query.return_value = \ 'SQL {env}' mock_snowflake.fetchall.return_value = [ (14, 'United Kingdom', 100000), (19, 'Global', 150000)] base_config.ENVIRONMENT = 'test' result = fetch_country_groups(None) mock_snowflake.session.execute.assert_called_with( 'SQL test') assert result == { 'country_groups': [ { 'country_group_id': 14, 'country_group_name': 'United Kingdom', 'country_group_floor': 100000 }, { 'country_group_id': 19, 'country_group_name': 'Global', 'country_group_floor': 150000 }]} def test_fetch_country_groups_with_country_groups(mock_snowflake): """Test fetching trending tracks country groups.""" with patch('activity_detector.flows.trending_tracks.tasks' '.fetch_country_groups.sql_loader') \ as mock_loader: country_groups = 'Nordics' base_config.ENVIRONMENT = 'test' mock_loader.load_query.return_value = \ '{env} {where_clause}' mock_snowflake.fetchall.return_value = [ (11, 'Nordics', 50000), (19, 'Global', 150000)] base_config.ENVIRONMENT = 'test' result = fetch_country_groups(None, country_groups=country_groups) mock_snowflake.session.execute.assert_called_with( 'test WHERE ttcg.trending_tracks_country_group_name in (' "'Nordics', 'Global')") assert result == { 'country_groups': [ { 'country_group_id': 11, 'country_group_name': 'Nordics', 'country_group_floor': 50000 }, { 'country_group_id': 19, 'country_group_name': 'Global', 'country_group_floor': 150000 }]} def test_fetch_country_groups_no_results(mock_snowflake): """Test fetching trending tracks country groups without db result.""" with patch('activity_detector.flows.trending_tracks.tasks' '.fetch_country_groups.sql_loader') \ as mock_loader: mock_loader.load_query.return_value = \ 'SQL {env}' mock_snowflake.fetchall.return_value = [] base_config.ENVIRONMENT = 'test' result = fetch_country_groups(None) mock_snowflake.session.execute.assert_called_with( 'SQL test') assert result == {'country_groups': []}