Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor add_warehouse_info_to_data
IKarbowiak83e20878417d
diff --git a/saleor/csv/utils/products_data.py b/saleor/csv/utils/products_data.pyindex 70e9077551..ba86982fbd 100644--- a/saleor/csv/utils/products_data.py+++ b/saleor/csv/utils/products_data.py@@ -242,11 +242,11 @@ def update_variant_data(if attribute_header:variant_attributes_headers.add(attribute_header)- result_data, headers = add_warehouse_info_to_data(+ result_data, header = add_warehouse_info_to_data(pk, warehouse_data, result_data)- if headers:- warehouse_headers.update(headers)+ if header:+ warehouse_headers.add(header)result_data = add_image_uris_to_data(pk, image, "variant_images", result_data)@@ -294,20 +294,19 @@ def add_attribute_info_to_data(def add_warehouse_info_to_data(pk: int, warehouse_data: Dict[str, Union[str, int]], result_data: Dict[int, dict],-) -> Tuple[Dict[int, dict], set]:+) -> Tuple[Dict[int, dict], Optional[str]]:"""Add info about stock quantity to variant data.- This functions adds info about stock quantity and quantity allocated to dict- with variant data. It returns updated data and warehouse header created based on- warehouse slug.+ This functions adds info about stock quantity to dict with variant data.+ It returns updated data and warehouse header created based on warehouse slug."""slug = warehouse_data["slug"]- warehouse_headers: Set[str] = set()+ warehouse_header = Noneif slug:warehouse_qty_header = f"{slug} (warehouse quantity)"if warehouse_qty_header not in result_data[pk]:result_data[pk][warehouse_qty_header] = warehouse_data["qty"]- warehouse_headers.add(warehouse_qty_header)+ warehouse_header = warehouse_qty_header- return result_data, warehouse_headers+ return result_data, warehouse_headerdiff --git a/tests/test_csv_products_data.py b/tests/test_csv_products_data.pyindex 9e4ac46e37..bc6de309f9 100644--- a/tests/test_csv_products_data.py+++ b/tests/test_csv_products_data.py@@ -286,11 +286,9 @@ def test_add_warehouse_info_to_data(product):input_data = {pk: {}}result, headers = add_warehouse_info_to_data(product.pk, warehouse_data, input_data)- expected_headers = [- f"{slug} (warehouse quantity)",- ]- assert result[pk][expected_headers[0]] == 12- assert headers == set(expected_headers)+ expected_header = f"{slug} (warehouse quantity)"+ assert result[pk][expected_header] == 12+ assert headers == expected_headerdef test_add_warehouse_info_to_data_data_not_changed(product):@@ -310,7 +308,7 @@ def test_add_warehouse_info_to_data_data_not_changed(product):result, headers = add_warehouse_info_to_data(product.pk, warehouse_data, input_data)assert result == input_data- assert headers == set()+ assert headers is Nonedef test_add_warehouse_info_to_data_data_no_slug(product):@@ -324,4 +322,4 @@ def test_add_warehouse_info_to_data_data_no_slug(product):result, headers = add_warehouse_info_to_data(product.pk, warehouse_data, input_data)assert result == input_data- assert headers == set()+ assert headers is None