def test_variant_pricing(variant: ProductVariant, monkeypatch, settings): taxed_price = TaxedMoney(Money("10.0", "USD"), Money("12.30", "USD")) monkeypatch.setattr( "saleor.product.utils.availability.apply_taxes_to_product", Mock(return_value=taxed_price), ) pricing = get_variant_availability(variant) assert pricing.price == taxed_price assert pricing.price_local_currency is None monkeypatch.setattr( "django_prices_openexchangerates.models.get_rates", lambda c: {"PLN": Mock(rate=2)}, ) settings.DEFAULT_COUNTRY = "PL" settings.OPENEXCHANGERATES_API_KEY = "fake-key" pricing = get_variant_availability(variant, local_currency="PLN") assert pricing.price_local_currency.currency == "PLN" assert pricing.available pricing = get_variant_availability(variant) assert pricing.price.tax.amount assert pricing.price_undiscounted.tax.amount assert pricing.price_undiscounted.tax.amount assert pricing.available
def test_variant_pricing(variant: ProductVariant, monkeypatch, settings, taxes): pricing = get_variant_availability(variant) assert pricing.price == variant.get_price() assert pricing.price_local_currency is None monkeypatch.setattr('django_prices_openexchangerates.models.get_rates', lambda c: {'PLN': Mock(rate=2)}) settings.DEFAULT_COUNTRY = 'PL' settings.OPENEXCHANGERATES_API_KEY = 'fake-key' pricing = get_variant_availability(variant, local_currency='PLN') assert pricing.price_local_currency.currency == 'PLN' assert pricing.available pricing = get_variant_availability(variant, taxes=taxes) assert pricing.price.tax.amount assert pricing.price_undiscounted.tax.amount assert pricing.price_undiscounted.tax.amount assert pricing.available
def test_variant_pricing(variant: ProductVariant, monkeypatch, settings, stock): taxed_price = TaxedMoney(Money("10.0", "USD"), Money("12.30", "USD")) monkeypatch.setattr(PluginsManager, "apply_taxes_to_product", Mock(return_value=taxed_price)) pricing = get_variant_availability(variant=variant, product=variant.product, collections=[], discounts=[]) assert pricing.price == taxed_price assert pricing.price_local_currency is None monkeypatch.setattr( "django_prices_openexchangerates.models.get_rates", lambda c: {"PLN": Mock(rate=2)}, ) settings.DEFAULT_COUNTRY = "PL" settings.OPENEXCHANGERATES_API_KEY = "fake-key" pricing = get_variant_availability( variant=variant, product=variant.product, collections=[], discounts=[], local_currency="PLN", country="US", ) assert pricing.price_local_currency.currency == "PLN" # type: ignore pricing = get_variant_availability(variant=variant, product=variant.product, collections=[], discounts=[]) assert pricing.price.tax.amount assert pricing.price_undiscounted.tax.amount assert pricing.price_undiscounted.tax.amount