def test_product_query_where(client): client.products.create( types.ProductDraft( key="test-product1", master_variant=types.ProductVariantDraft( prices=[ types.PriceDraft( country="NL", value=types.CentPrecisionMoneyDraft( cent_amount=8750, currency_code="EUR" ), ) ] ), ) ) client.products.create( types.ProductDraft( key="test-product-2", master_variant=types.ProductVariantDraft( prices=[ types.PriceDraft( country="UK", value=types.CentPrecisionMoneyDraft( cent_amount=8750, currency_code="EUR" ), ) ] ), ) ) client.products.create(types.ProductDraft(key="test-product2")) result = client.products.query( where="masterData(staged(masterVariant(prices(country='NL'))))" ) assert len(result.results) == 1 assert result.total == 1 result = client.products.query( where="masterData(staged(masterVariant(prices(country='UK'))))" ) assert len(result.results) == 1 assert result.total == 1 result = client.products.query( where="masterData(staged(masterVariant(prices(country='UK' or country='NL'))))" ) assert len(result.results) == 2 assert result.total == 2
def test_products_create(client): custom_type = client.types.create( types.TypeDraft(name=types.LocalizedString(en="myType"), resource_type_ids=[types.ResourceTypeId.ASSET], field_definitions=[types.FieldDefinition(name="foo")])) assert custom_type.id draft = types.ProductDraft( key="test-product", publish=True, master_variant=types.ProductVariantDraft( assets=[ types.AssetDraft(custom=types.CustomFieldsDraft( type=types.TypeResourceIdentifier(id=custom_type.id), fields=types.FieldContainer(foo="bar"), )) ], prices=[ types.PriceDraft( value=types.CentPrecisionMoneyDraft(cent_amount=1000, currency_code="EUR"), country="NL", ) ], ), ) product = client.products.create(draft) assert product.id assert product.master_data.current.master_variant.assets assert product.master_data.current.master_variant.prices
def post_load(self, data, **kwargs): del data["type"] return types.CentPrecisionMoneyDraft(**data)
def test_product_query_where(client): client.products.create( types.ProductDraft( key="test-product1", name=types.LocalizedString(en=f"my-product-1"), slug=types.LocalizedString(en=f"my-product-1"), product_type=types.ProductTypeResourceIdentifier(key="dummy"), master_variant=types.ProductVariantDraft( prices=[ types.PriceDraft( country="NL", value=types.CentPrecisionMoneyDraft( cent_amount=8750, currency_code="EUR" ), ) ] ), ) ) client.products.create( types.ProductDraft( key="test-product-2", name=types.LocalizedString(en=f"my-product-1"), slug=types.LocalizedString(en=f"my-product-1"), product_type=types.ProductTypeResourceIdentifier(key="dummy"), master_variant=types.ProductVariantDraft( prices=[ types.PriceDraft( country="UK", value=types.CentPrecisionMoneyDraft( cent_amount=8750, currency_code="EUR" ), ) ] ), ) ) client.products.create( types.ProductDraft( key="test-product2", name=types.LocalizedString(en=f"my-product-1"), slug=types.LocalizedString(en=f"my-product-1"), product_type=types.ProductTypeResourceIdentifier(key="dummy"), ) ) result = client.products.query( where="masterData(staged(masterVariant(prices(country='NL'))))" ) assert len(result.results) == 1 assert result.total == 1 result = client.products.query( where="masterData(staged(masterVariant(prices(country='UK'))))" ) assert len(result.results) == 1 assert result.total == 1 result = client.products.query( where="masterData(staged(masterVariant(prices(country='UK' or country='NL'))))" ) assert len(result.results) == 2 assert result.total == 2