Skip to content

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

Add tests for filter_range_field

IKarbowiakb2ff46a6ee8e
diff --git a/tests/api/test_core.py b/tests/api/test_core.py
index 4994230380..b0bf58680c 100644
--- a/tests/api/test_core.py
+++ b/tests/api/test_core.py
@@ -18,7 +18,11 @@ from saleor.graphql.core.utils import (
validate_slug_and_generate_if_needed,
)
from saleor.graphql.product import types as product_types
-from saleor.graphql.utils import get_database_id, reporting_period_to_date
+from saleor.graphql.utils import (
+ filter_range_field,
+ get_database_id,
+ reporting_period_to_date,
+)
from saleor.product.models import Category, Product
from tests.api.utils import _get_graphql_content_from_response, get_graphql_content
@@ -347,3 +351,23 @@ def test_validate_slug_and_generate_if_needed_not_raises_errors(
def test_validate_slug_and_generate_if_needed_generate_slug(cleaned_input):
category = Category(name="test")
validate_slug_and_generate_if_needed(category, "name", cleaned_input)
+
+
+ "value, count, product_indexes",
+ [
+ ({"lte": 50, "gte": 25}, 1, [2]),
+ ({"lte": 25}, 2, [0, 1]),
+ ({"lte": 10}, 1, [0]),
+ ({"gte": 40}, 0, []),
+ ],
+)
+def test_filter_range_field(value, count, product_indexes, product_list):
+ qs = Product.objects.all().order_by("pk")
+ field = "price_amount"
+
+ result = filter_range_field(qs, field, value)
+
+ expected_products = [qs[index] for index in product_indexes]
+ assert result.count() == count
+ assert list(result) == expected_products
diff --git a/tests/conftest.py b/tests/conftest.py
index b7b28ff445..9cdc5fa588 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -849,7 +849,7 @@ def product_list(product_type, category, warehouse):
pk=1489,
name="Test product 3",
slug="test-product-c",
- price=Money(20, "USD"),
+ price=Money(30, "USD"),
category=category,
product_type=product_type,
is_published=True,
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index 027fcd1a05..62baf77ce0 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -432,7 +432,7 @@ def test_get_discount_for_checkout_entire_order_voucher_not_applicable(
(5, DiscountValueType.FIXED, False, 15),
(10000, DiscountValueType.FIXED, True, 10),
(10, DiscountValueType.PERCENTAGE, True, 1),
- (10, DiscountValueType.PERCENTAGE, False, 5),
+ (10, DiscountValueType.PERCENTAGE, False, 6),
],
)
def test_get_discount_for_checkout_specific_products_voucher(