"""Unit tests for generation_utils module.""" import pytest from salessheets.utils import generation_utils @pytest.mark.parametrize('template_details, sheet_label, price_field', ( ({'name': 'CAN', 'full_name': 'Canada'}, 'CAN Price', 'price_code'), ( {'name': 'EU', 'full_name': 'Europe'}, 'EUR Price Code', 'store_pricing_tier_name' ), ( {'name': 'USA', 'full_name': 'United States'}, 'US Price Code', 'store_pricing_tier_name' ), )) def test_extract_price_data_for_localized_template( template_details, sheet_label, price_field): """Test extract_price_data_for_localized_template extracts data.""" pricing_data = { 'price_code': '13.99', 'store_pricing_tier_name': 'Wheels CD Tier #8'} label, price = generation_utils.extract_price_data_for_localized_template( template_details, pricing_data) assert label == sheet_label assert price == pricing_data[price_field] def test_compose_address_for_localized(): """Expects that compose_address_for_localized returns correct string.""" template_name = 'TEST' contact_data_format_mapping = { 'TEST': ( '{apartment} {street}\n{city}, {state} {postal_code}\n{country}\n' '{telephone}' ) } contact_data = { 'apartment': 111, 'street': 'New Street', 'city': 'New York', 'state': 'NY', 'postal_code': 876, 'country': 'USA', 'telephone': '' } result = generation_utils.compose_address_for_localized( template_name, contact_data_format_mapping, contact_data) assert result == '111 New Street\nNew York, NY 876\nUSA\n' @pytest.mark.parametrize('template_details, expected_label', ( ({'name': 'CAN', 'full_name': 'Canada'}, 'CAN Price'), ({'name': 'EU', 'full_name': 'Europe'}, 'EUR Price'))) def test_extract_price_data_for_localized_template_custom_price( template_details, expected_label): """Test function always extracts Price Code for custom prices.""" pricing_data = { 'price_code': '13.99', 'store_pricing_tier_name': 'Custom'} label, price = generation_utils.extract_price_data_for_localized_template( template_details, pricing_data) assert label == expected_label assert price == pricing_data['price_code']