Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test adding sale with product or category
Anna Siwik7eb35a3eee3c
diff --git a/tests/dashboard/test_discount.py b/tests/dashboard/test_discount.pyindex 7b5ecca4ca..7a580ec311 100644--- a/tests/dashboard/test_discount.py+++ b/tests/dashboard/test_discount.py@@ -42,3 +42,50 @@ def test_voucher_shipping_add(admin_client):assert voucher.discount_value_type == DiscountValueType.FIXEDassert voucher.discount_value == Decimal('15.99')assert voucher.limit == Money('59.99', 'USD')+++def test_view_sale_add(admin_client, default_category):+ url = reverse('dashboard:sale-add')+ data = {+ 'name': 'Free products',+ 'type': DiscountValueType.PERCENTAGE,+ 'value': 100,+ 'categories': [default_category.id]}++ response = admin_client.post(url, data)++ assert response.status_code == 302+ assert Sale.objects.count() == 1+ sale = Sale.objects.first()+ assert sale.name == data['name']+ assert default_category in sale.categories.all()+++def test_view_sale_add_requires_product_or_category(+ admin_client, default_category, product_in_stock):+ url = reverse('dashboard:sale-add')+ data = {+ 'name': 'Free products',+ 'type': DiscountValueType.PERCENTAGE,+ 'value': 100}++ response = admin_client.post(url, data)++ assert response.status_code == 200+ assert Sale.objects.count() == 0++ data_with_category = data.copy()+ data_with_category.update({'categories': [default_category.id]})++ response = admin_client.post(url, data_with_category)++ assert response.status_code == 302+ assert Sale.objects.count() == 1++ data_with_product = data.copy()+ data_with_product.update({'products': [product_in_stock.id]})++ response = admin_client.post(url, data_with_product)++ assert response.status_code == 302+ assert Sale.objects.count() == 2