Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Test old managers methods

Anna Siwik185e1aad88e8
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index 1932a03ffe..d822e184aa 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -10,6 +10,8 @@ from saleor.cart.utils import get_category_variants_and_prices
from saleor.checkout.core import Checkout
from saleor.discount.forms import CheckoutDiscountForm
from saleor.discount.models import NotApplicable, Sale, Voucher
+from saleor.discount.utils import (
+ decrease_voucher_usage, increase_voucher_usage)
from saleor.product.models import Category, Product, ProductVariant
@@ -317,3 +319,23 @@ def test_get_category_variants_and_prices_product_with_many_categories(
discount = voucher.get_discount_for_checkout(checkout_mock)
# 10% of 10.00 is 1.00
assert discount.amount == Price('1.00', currency=discount.amount.currency)
+
+
+def test_increase_voucher_usage():
+ voucher = Voucher.objects.create(
+ code='unique', type=Voucher.VALUE_TYPE,
+ discount_value_type=Voucher.DISCOUNT_VALUE_FIXED,
+ discount_value=10, usage_limit=100)
+ increase_voucher_usage(voucher)
+ voucher.refresh_from_db()
+ assert voucher.used == 1
+
+
+def test_decrease_voucher_usage():
+ voucher = Voucher.objects.create(
+ code='unique', type=Voucher.VALUE_TYPE,
+ discount_value_type=Voucher.DISCOUNT_VALUE_FIXED,
+ discount_value=10, usage_limit=100, used=10)
+ decrease_voucher_usage(voucher)
+ voucher.refresh_from_db()
+ assert voucher.used == 9
diff --git a/tests/test_product.py b/tests/test_product.py
index cf26198ec4..5c300f8896 100644
--- a/tests/test_product.py
+++ b/tests/test_product.py
@@ -109,6 +109,22 @@ def test_availability(product_in_stock, monkeypatch, settings):
assert availability.available
+def test_available_products_only_published(product_list):
+ available_products = models.Product.objects.available_products()
+ assert available_products.count() == 2
+ assert all([product.is_published for product in available_products])
+
+
+def test_available_products_only_available(product_list):
+ product = product_list[0]
+ date_tomorrow = datetime.date.today() + datetime.timedelta(days=1)
+ product.available_on = date_tomorrow
+ product.save()
+ available_products = models.Product.objects.available_products()
+ assert available_products.count() == 1
+ assert all([product.is_available() for product in available_products])
+
+
def test_filtering_by_attribute(db, color_attribute):
product_class_a = models.ProductClass.objects.create(
name='New class', has_variants=True)