def test_availability(product, monkeypatch, settings):
    taxed_price = TaxedMoney(Money("10.0", "USD"), Money("12.30", "USD"))
    monkeypatch.setattr(ExtensionsManager, "apply_taxes_to_product",
                        Mock(return_value=taxed_price))
    availability = get_product_availability(product)
    taxed_price_range = TaxedMoneyRange(start=taxed_price, stop=taxed_price)
    assert availability.price_range == taxed_price_range
    assert availability.price_range_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"
    availability = get_product_availability(product, local_currency="PLN")
    assert availability.price_range_local_currency.start.currency == "PLN"
    assert availability.available

    availability = get_product_availability(product)
    assert availability.price_range.start.tax.amount
    assert availability.price_range.stop.tax.amount
    assert availability.price_range_undiscounted.start.tax.amount
    assert availability.price_range_undiscounted.stop.tax.amount
    assert availability.available
示例#2
0
def test_availability(stock, monkeypatch, settings):
    product = stock.product_variant.product
    taxed_price = TaxedMoney(Money("10.0", "USD"), Money("12.30", "USD"))
    monkeypatch.setattr(PluginsManager, "apply_taxes_to_product",
                        Mock(return_value=taxed_price))
    availability = get_product_availability(
        product=product,
        variants=product.variants.all(),
        collections=[],
        discounts=[],
        country="PL",
    )
    taxed_price_range = TaxedMoneyRange(start=taxed_price, stop=taxed_price)
    assert availability.price_range == taxed_price_range
    assert availability.price_range_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"
    availability = get_product_availability(
        product=product,
        variants=product.variants.all(),
        collections=[],
        discounts=[],
        local_currency="PLN",
        country="PL",
    )
    assert availability.price_range_local_currency.start.currency == "PLN"

    availability = get_product_availability(
        product=product,
        variants=product.variants.all(),
        collections=[],
        discounts=[],
        country="PL",
    )
    assert availability.price_range.start.tax.amount
    assert availability.price_range.stop.tax.amount
    assert availability.price_range_undiscounted.start.tax.amount
    assert availability.price_range_undiscounted.stop.tax.amount
def test_availability(product, monkeypatch, settings, taxes):
    availability = get_product_availability(product)
    assert availability.price_range == product.get_price_range()
    assert availability.price_range_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'
    availability = get_product_availability(product, local_currency='PLN')
    assert availability.price_range_local_currency.start.currency == 'PLN'
    assert availability.available

    availability = get_product_availability(product, taxes=taxes)
    assert availability.price_range.start.tax.amount
    assert availability.price_range.stop.tax.amount
    assert availability.price_range_undiscounted.start.tax.amount
    assert availability.price_range_undiscounted.stop.tax.amount
    assert availability.available
def test_availability(product, monkeypatch, settings, taxes):
    availability = get_product_availability(product)
    assert availability.price_range == product.get_price_range()
    assert availability.price_range_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"
    availability = get_product_availability(product, local_currency="PLN")
    assert availability.price_range_local_currency.start.currency == "PLN"
    assert availability.available

    availability = get_product_availability(product, taxes=taxes)
    assert availability.price_range.start.tax.amount
    assert availability.price_range.stop.tax.amount
    assert availability.price_range_undiscounted.start.tax.amount
    assert availability.price_range_undiscounted.stop.tax.amount
    assert availability.available