def test_correlation_id_is_set_in_exception(client): product = client.products.create( types.ProductDraft( key="test-product", name=types.LocalizedString(en=f"my-product"), slug=types.LocalizedString(en=f"my-product"), product_type=types.ProductTypeResourceIdentifier(key="dummy"), )) product = client.products.update_by_id( id=product.id, version=product.version, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString( nl="nl-slug2")) ], ) # This should raise a version conflict error with pytest.raises(CommercetoolsError) as exc: client.products.update_by_id( id=product.id, version=1, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString( nl="nl-slug3")) ], ) assert exc.value.correlation_id is not None
def test_product_update(client): """Test the return value of the update methods. It doesn't test the actual update itself. TODO: See if this is worth testing since we're using a mocking backend """ product = client.products.create(types.ProductDraft(key="test-product")) assert uuid.UUID(product.id) assert product.key == "test-product" product = client.products.update_by_id( id=product.id, version=product.version, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString(nl="nl-slug2")) ], ) assert product.key == "test-product" product = client.products.update_by_key( key="test-product", version=product.version, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString(nl="nl-slug2")) ], ) assert product.key == "test-product"
def test_product_update(client): """Test the return value of the update methods. It doesn't test the actual update itself. TODO: See if this is worth testing since we're using a mocking backend """ product = client.products.create( types.ProductDraft( key="test-product", master_variant=types.ProductVariantDraft(sku="1", key="1"), )) assert uuid.UUID(product.id) assert product.key == "test-product" product = client.products.update_by_id( id=product.id, version=product.version, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString( nl="nl-slug2")) ], ) assert product.key == "test-product" assert product.master_data.published is False product = client.products.update_by_id( id=product.id, version=product.version, actions=[types.ProductPublishAction()]) assert product.master_data.published is True assert not product.master_data.current.master_variant.prices product = client.products.update_by_id( id=product.id, version=product.version, actions=[ types.ProductSetPricesAction( sku="1", prices=[ types.PriceDraft(value=types.Money(cent_amount=1000, currency_code="GBP")) ], staged=False, ) ], ) assert len(product.master_data.current.master_variant.prices) == 1 product = client.products.update_by_key( key="test-product", version=product.version, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString( nl="nl-slug2")) ], ) assert product.key == "test-product"
def test_resource_update_conflict(client): """Test the return value of the update methods. It doesn't test the actual update itself. TODO: See if this is worth testing since we're using a mocking backend """ product = client.products.create( types.ProductDraft( key="test-product", product_type=types.ProductTypeResourceIdentifier(key="dummy"), name={"en": "my-product"}, slug={"en": "foo-bar"}, )) assert product.version == 1 assert uuid.UUID(product.id) assert product.key == "test-product" product = client.products.update_by_id( id=product.id, version=product.version, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString( nl="nl-slug2")) ], ) assert product.key == "test-product" assert product.version == 2 # This should raise a version conflict error with pytest.raises(CommercetoolsError) as exc: product = client.products.update_by_id( id=product.id, version=1, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString( nl="nl-slug3")) ], ) assert exc.value.response.status_code == 409 assert exc.value.response.errors[0].current_version == 2 # Force it product = client.products.update_by_id( id=product.id, version=1, actions=[ types.ProductChangeSlugAction(slug=types.LocalizedString( nl="nl-slug2")) ], force_update=True, )