Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add tests for updating product after changing default currency
IKarbowiaka45142f53f6f
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex 68aaae7a83..d1da94929c 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -1924,6 +1924,75 @@ def test_product_create_with_collections_webhook(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+ }+ }+ }+"""++def test_update_product(staff_api_client,category,@@ -1934,74 +2003,7 @@ def test_update_product(monkeypatch,color_attribute,):- query = """- 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- }- }- }- """-+ query = MUTATION_UPDATE_PRODUCTother_description_json = json.dumps(other_description_json)product_id = graphene.Node.to_global_id("Product", product.pk)@@ -2063,6 +2065,86 @@ def test_update_product(assert attributes[0]["values"][0]["slug"] == "rainbow"+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(