Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix empty country code in Address input (#18486)
Filip Owczarekafa70a6efc05
diff --git a/saleor/core/utils/country.py b/saleor/core/utils/country.pyindex d2470d8dc2..feb8f39ddf 100644--- a/saleor/core/utils/country.py+++ b/saleor/core/utils/country.py@@ -24,7 +24,7 @@ def get_active_country(To get country code from address data from mutation input use address_data parameter"""- if address_data is not None:+ if address_data is not None and address_data.country:return address_data.countryif shipping_address:diff --git a/saleor/tax/tests/test_utils.py b/saleor/tax/tests/test_utils.pyindex c99975b2e7..51dece2908 100644--- a/saleor/tax/tests/test_utils.py+++ b/saleor/tax/tests/test_utils.py@@ -1,4 +1,5 @@from decimal import Decimal+from unittest.mock import Mockimport pytest@@ -121,6 +122,34 @@ def test_get_tax_country_fallbacks_to_channel_country(channel_USD):assert country == channel_USD.default_country.code+def test_get_tax_country_use_address_data(+ channel_USD,+):+ # given+ address_data = Mock()+ address_data.country = "PL"++ # when+ country = get_active_country(channel_USD, address_data=address_data)++ # then+ assert country == "PL"+++def test_get_tax_country_fallbacks_to_channel_country_address_data_with_empty_country(+ channel_USD,+):+ # given+ address_data = Mock()+ address_data.country = None++ # when+ country = get_active_country(channel_USD, address_data=address_data)++ # then+ assert country == channel_USD.default_country.code++def test_get_shipping_tax_rate_for_checkout_weighted_tax(checkout_with_items, channel_USD, plugins_manager, shipping_method):