"""Unit tests for Pandora util functions.""" from feed_ingestion.flows.pandora import util def test_build_cases_by_country_pass_default_case(): """Test CASE statement for country mappings with default case passed.""" country_mappings = {'US': 'USA'} cases = util.build_cases_by_country( mapping=country_mappings, default_case='default') expected = " CASE WHEN r.country = 'US' THEN 'USA' ELSE default END " assert cases == expected def test_build_cases_by_country_no_default_case_passed(): """Test CASE statement for country mappings with no default case passed.""" country_mappings = {'US': 'USA'} cases = util.build_cases_by_country(mapping=country_mappings) expected = " CASE WHEN r.country = 'US' THEN 'USA' ELSE NULL END " assert cases == expected def test_build_cases_by_country_numeric_values(): """Test CASE statement for country mappings with numeric values.""" country_mappings = {'US': 170} cases = util.build_cases_by_country(mapping=country_mappings) expected = " CASE WHEN r.country = 'US' THEN 170 ELSE NULL END " assert cases == expected def test_build_cases_by_country_multiple_countries(): """Test CASE statement for country mappings with multiple countries.""" country_mappings = {'US': 'USA', 'CAN': 'Canada'} cases = util.build_cases_by_country(mapping=country_mappings) expected_us_first = " CASE WHEN r.country = 'US' THEN 'USA' " \ "WHEN r.country = 'CAN' THEN 'Canada' ELSE NULL END " expected_can_first = " CASE WHEN r.country = 'CAN' THEN 'Canada' " \ "WHEN r.country = 'US' THEN 'USA' ELSE NULL END " assert cases == expected_us_first or cases == expected_can_first