Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix tests when working with a native extension of maxminddb
Patryk Zawadzkiffea55d251d7
diff --git a/saleor/core/tests/test_core.py b/saleor/core/tests/test_core.pyindex f2bf2644a3..720ac39b07 100644--- a/saleor/core/tests/test_core.py+++ b/saleor/core/tests/test_core.py@@ -56,7 +56,9 @@ type_schema = {],)def test_get_country_by_ip(ip_data, expected_country, monkeypatch):- monkeypatch.setattr("saleor.core.utils.georeader.get", Mock(return_value=ip_data))+ monkeypatch.setattr(+ "saleor.core.utils._get_geo_data_by_ip", Mock(return_value=ip_data)+ )country = get_country_by_ip("127.0.0.1")assert country == expected_countrydiff --git a/saleor/core/utils/__init__.py b/saleor/core/utils/__init__.pyindex 7123a3490d..6343e4d3ba 100644--- a/saleor/core/utils/__init__.py+++ b/saleor/core/utils/__init__.py@@ -68,8 +68,15 @@ def is_valid_ipv6(ip: str) -> bool:return True+def _get_geo_data_by_ip(ip_address):+ # This function is here to make it easier to mock the GeoIP+ # as the georeader object below can be a native platform library+ # that does not support monkeypatching.+ return georeader.get(ip_address)++def get_country_by_ip(ip_address):- geo_data = georeader.get(ip_address)+ geo_data = _get_geo_data_by_ip(ip_address)if geo_data and "country" in geo_data and "iso_code" in geo_data["country"]:country_iso_code = geo_data["country"]["iso_code"]if country_iso_code in countries: