Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Merge branch 'master' of github.com:mirumee/saleor into feature/product_updated_webhook

Tomasz Szymanskicb3e86a9316d
diff --cc saleor/graphql/product/tests/test_product.py
index d13ab6d42c,76848ba84f..cd79400565
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@@ -1887,9 -1925,76 +1925,78 @@@ def test_product_create_with_collection
get_graphql_content(response)
+ MUTATION_UPDATE_PRODUCT = """
+ mutation updateProduct(
+ $productId: ID!,
+ $categoryId: ID!,
+ $name: String!,
+ $slug: String!,
+ $descriptionJson: JSONString!,
+ $isPublished: Boolean!,
+ $visibleInListings: Boolean!,
+ $chargeTaxes: Boolean!,
+ $taxCode: String!,
+ $basePrice: PositiveDecimal!,
+ $attributes: [AttributeValueInput!]) {
+ productUpdate(
+ id: $productId,
+ input: {
+ category: $categoryId,
+ name: $name,
+ slug: $slug,
+ descriptionJson: $descriptionJson,
+ isPublished: $isPublished,
+ visibleInListings: $visibleInListings,
+ chargeTaxes: $chargeTaxes,
+ taxCode: $taxCode,
+ basePrice: $basePrice,
+ attributes: $attributes
+ }) {
+ product {
+ category {
+ name
+ }
+ descriptionJson
+ isPublished
+ chargeTaxes
+ variants {
+ price {
+ amount
+ }
+ }
+ taxType {
+ taxCode
+ description
+ }
+ name
+ slug
+ productType {
+ name
+ }
+ attributes {
+ attribute {
+ id
+ name
+ }
+ values {
+ name
+ slug
+ }
+ }
+ visibleInListings
+ }
+ errors {
+ message
+ field
+ }
+ }
+ }
+ """
+
+
+@patch("saleor.plugins.manager.PluginsManager.product_updated")
def test_update_product(
+ updated_webhook_mock,
staff_api_client,
category,
non_default_category,
@@@ -2027,9 -2065,87 +2067,89 @@@
assert attributes[0]["values"][0]["name"] == "Rainbow"
assert attributes[0]["values"][0]["slug"] == "rainbow"
+ updated_webhook_mock.assert_called_once_with(product)
+
+ def test_update_product_when_default_currency_changeed(
+ staff_api_client,
+ category,
+ non_default_category,
+ product,
+ other_description_json,
+ permission_manage_products,
+ monkeypatch,
+ color_attribute,
+ settings,
+ ):
+ # Ensure that when default currency has changed, there is no errors
+ # when updating products with different currency which has different number
+ # of required decimal places
+
+ settings.DEFAULT_COUNTRY = "IS"
+ settings.DEFAULT_CURRENCY = "ISK"
+ query = MUTATION_UPDATE_PRODUCT
+
+ other_description_json = json.dumps(other_description_json)
+
+ product_id = graphene.Node.to_global_id("Product", product.pk)
+ category_id = graphene.Node.to_global_id("Category", non_default_category.pk)
+ product_name = "updated name"
+ product_slug = "updated-product"
+ product_is_published = True
+ product_visible_in_listings = False
+ product_charge_taxes = True
+ basePrice = 10.00
+ product_tax_rate = "STANDARD"
+
+ # Mock tax interface with fake response from tax gateway
+ monkeypatch.setattr(
+ PluginsManager,
+ "get_tax_code_from_object_meta",
+ lambda self, x: TaxType(description="", code=product_tax_rate),
+ )
+
+ attribute_id = graphene.Node.to_global_id("Attribute", color_attribute.pk)
+
+ variables = {
+ "productId": product_id,
+ "categoryId": category_id,
+ "name": product_name,
+ "slug": product_slug,
+ "descriptionJson": other_description_json,
+ "isPublished": product_is_published,
+ "visibleInListings": product_visible_in_listings,
+ "chargeTaxes": product_charge_taxes,
+ "taxCode": product_tax_rate,
+ "basePrice": basePrice,
+ "attributes": [{"id": attribute_id, "values": ["Rainbow"]}],
+ }
+
+ response = staff_api_client.post_graphql(
+ query, variables, permissions=[permission_manage_products]
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["productUpdate"]
+ assert data["errors"] == []
+ assert data["product"]["name"] == product_name
+ assert data["product"]["slug"] == product_slug
+ assert data["product"]["descriptionJson"] == other_description_json
+ assert data["product"]["isPublished"] == product_is_published
+ assert data["product"]["visibleInListings"] == product_visible_in_listings
+ assert data["product"]["chargeTaxes"] == product_charge_taxes
+ assert data["product"]["variants"][0]["price"]["amount"] == basePrice
+ assert data["product"]["taxType"]["taxCode"] == product_tax_rate
+ assert not data["product"]["category"]["name"] == category.name
+
+ attributes = data["product"]["attributes"]
+
+ assert len(attributes) == 1
+ assert len(attributes[0]["values"]) == 1
+
+ assert attributes[0]["attribute"]["id"] == attribute_id
+ assert attributes[0]["values"][0]["name"] == "Rainbow"
+ assert attributes[0]["values"][0]["slug"] == "rainbow"
+
+
UPDATE_PRODUCT_SLUG_MUTATION = """
mutation($id: ID!, $slug: String) {
productUpdate(