Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve tests and currency conversion
Artur Smętec486ffbe180
diff --git a/saleor/product/utils.py b/saleor/product/utils.pyindex d4db4f6d9e..93ec6e378d 100644--- a/saleor/product/utils.py+++ b/saleor/product/utils.py@@ -1,6 +1,6 @@from collections import namedtuple-from django_prices_openexchangerates import exchange_currency+from ..core.utils import to_local_currencyfrom .models import Product@@ -45,11 +45,11 @@ def get_pricing_info(product, discounts=None, local_currency=None):# Local currencyif local_currency:- price_range_local = exchange_currency(+ price_range_local = to_local_currency(price_range, local_currency)- undiscounted_local = exchange_currency(+ undiscounted_local = to_local_currency(uncdiscounted, local_currency)- if undiscounted_local.min_price > price_range_local.min_price:+ if undiscounted_local and undiscounted_local.min_price > price_range_local.min_price:discount_local_currency = (undiscounted_local.min_price - price_range_local.min_price)else:diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 85740c95a0..8ed4c9cd50 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -8,7 +8,7 @@ from django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom ..cart.decorators import get_cart_from_request-from ..core.utils import get_paginator_items, to_local_currency+from ..core.utils import get_paginator_itemsfrom .forms import get_form_class_for_productfrom .models import Categoryfrom .utils import (products_with_details,diff --git a/tests/test_product.py b/tests/test_product.pyindex c23e23c850..bdce47c4cf 100644--- a/tests/test_product.py+++ b/tests/test_product.py@@ -41,36 +41,15 @@ def test_product_preview(admin_client, client, product_in_stock):assert response.status_code == 200-def test_product_page_without_openexchagerates(- client, product_in_stock, settings):- settings.OPENEXCHANGERATES_API_KEY = None- response = client.get(product_in_stock.get_absolute_url())- context = response.context- assert context['local_price_range'] is None---def test_product_page_with_openexchagerates(- client, monkeypatch, product_in_stock, settings):- settings.DEFAULT_CURRENCY = 'USD'- settings.DEFAULT_COUNTRY = 'PL'- settings.OPENEXCHANGERATES_API_KEY = 'fake-key'- response = client.get(product_in_stock.get_absolute_url())- context = response.context- assert context['local_price_range'] is None- monkeypatch.setattr(- 'django_prices_openexchangerates.models.get_rates',- lambda c: {'PLN': Mock(rate=2)})- response = client.get(product_in_stock.get_absolute_url())- context = response.context- assert context['local_price_range'].min_price.currency == 'PLN'---def test_pricing_info(product_in_stock, monkeypatch):+def test_pricing_info(product_in_stock, monkeypatch, settings):pricing_info = get_pricing_info(product_in_stock)assert pricing_info.price_range == product_in_stock.get_price_range()assert pricing_info.price_range_local_currency is Nonemonkeypatch.setattr('django_prices_openexchangerates.models.get_rates',lambda c: {'PLN': Mock(rate=2)})+ settings.DEFAULT_CURRENCY = 'USD'+ settings.DEFAULT_COUNTRY = 'PL'+ settings.OPENEXCHANGERATES_API_KEY = 'fake-key'pricing_info = get_pricing_info(product_in_stock, local_currency='PLN')assert pricing_info.price_range_local_currency.min_price.currency == 'PLN'