feat: added product filter tests
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from shop.tests.mixins import CreateProductsMixin
|
||||
from shop.models import Product
|
||||
from shop.filters import ProductFilter
|
||||
|
||||
|
||||
class TestProductFilter(TestCase, CreateProductsMixin):
|
||||
def setUp(self):
|
||||
product_a = self.create_product(name="producto 1", sku='001', price=Decimal("40.00"))
|
||||
product_b = self.create_product(name="producto 2", sku='002', price=Decimal("70.00"))
|
||||
product_c = self.create_product(name="producto 3", sku='003', price=Decimal("100.00"))
|
||||
|
||||
def test_product_filter_by_price(self):
|
||||
f = ProductFilter({"price_gt": "40"})
|
||||
f.is_valid()
|
||||
qs = f.filter_queryset(Product.objects.all())
|
||||
assert qs.count() == 3
|
||||
|
||||
f = ProductFilter({"price_lt": "40"})
|
||||
f.is_valid()
|
||||
qs = f.filter_queryset(Product.objects.all())
|
||||
assert qs.count() == 0
|
||||
|
||||
f = ProductFilter({"price_gt": "100"})
|
||||
f.is_valid()
|
||||
qs = f.filter_queryset(Product.objects.all())
|
||||
assert qs.count() == 1
|
||||
Reference in New Issue
Block a user