Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Don't alter the behavior
Patryk Zawadzki609e7957bec9
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex 0c985c8829..9550553387 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -87,8 +87,9 @@ def product_class_delete(request, pk):'Dashboard message','Deleted product type %s') % product_class)return redirect('dashboard:product-class-list')- ctx = {'product_class': product_class,- 'products': product_class.products.all()}+ ctx = {+ 'product_class': product_class,+ 'products': product_class.products.all()}return TemplateResponse(request,'dashboard/product/product_class/modal/confirm_delete.html',diff --git a/saleor/product/migrations/0036_auto_20171109_1308.py b/saleor/product/migrations/0036_auto_20171109_1308.pydeleted file mode 100644index 0cb949e8f6..0000000000--- a/saleor/product/migrations/0036_auto_20171109_1308.py+++ /dev/null@@ -1,26 +0,0 @@-# -*- coding: utf-8 -*--# Generated by Django 1.11.5 on 2017-11-09 19:08-from __future__ import unicode_literals--from django.db import migrations, models-import django.db.models.deletion---class Migration(migrations.Migration):-- dependencies = [- ('product', '0035_auto_20170919_0846'),- ]-- operations = [- migrations.AlterField(- model_name='product',- name='product_class',- field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='products', to='product.ProductClass', verbose_name='product class'),- ),- migrations.AlterField(- model_name='stock',- name='location',- field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='product.StockLocation'),- ),- ]diff --git a/saleor/product/models.py b/saleor/product/models.pyindex f474d2c4d6..dbbd30a579 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -122,7 +122,7 @@ class Product(models.Model, ItemRange, index.Indexed):product_class = models.ForeignKey(ProductClass, related_name='products',verbose_name=pgettext_lazy('Product field', 'product class'),- on_delete=models.PROTECT)+ on_delete=models.CASCADE)name = models.CharField(pgettext_lazy('Product field', 'name'), max_length=128)description = models.TextField(@@ -376,7 +376,7 @@ class Stock(models.Model):verbose_name=pgettext_lazy('Stock item field', 'variant'),on_delete=models.CASCADE)location = models.ForeignKey(- StockLocation, null=True, on_delete=models.PROTECT)+ StockLocation, null=True, on_delete=models.CASCADE)quantity = models.IntegerField(pgettext_lazy('Stock item field', 'quantity'),validators=[MinValueValidator(0)], default=Decimal(1))diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.pyindex e4217c7de0..93170b56b2 100644--- a/tests/dashboard/test_product.py+++ b/tests/dashboard/test_product.py@@ -39,7 +39,8 @@ def test_stock_record_update_works(admin_client, product_in_stock):quantity = stock.quantityquantity_allocated = stock.quantity_allocatedurl = reverse(- 'dashboard:variant-stock-update', kwargs={+ 'dashboard:variant-stock-update',+ kwargs={'product_pk': product_in_stock.pk,'variant_pk': variant.pk,'stock_pk': stock.pk})@@ -53,10 +54,11 @@ def test_stock_record_update_works(admin_client, product_in_stock):def test_valid_product_class_form(color_attribute, size_attribute):- data = {'name': "Testing Class",- 'product_attributes': [color_attribute.pk],- 'variant_attributes': [size_attribute.pk],- 'has_variants': True}+ data = {+ 'name': "Testing Class",+ 'product_attributes': [color_attribute.pk],+ 'variant_attributes': [size_attribute.pk],+ 'has_variants': True}form = ProductClassForm(data)assert form.is_valid()@@ -68,25 +70,27 @@ def test_valid_product_class_form(color_attribute, size_attribute):def test_variantless_product_class_form(color_attribute, size_attribute):- data = {'name': "Testing Class",- 'product_attributes': [color_attribute.pk],- 'variant_attributes': [],- 'has_variants': False}+ data = {+ 'name': "Testing Class",+ 'product_attributes': [color_attribute.pk],+ 'variant_attributes': [],+ 'has_variants': False}form = ProductClassForm(data)assert form.is_valid()# Don't allow variant attributes when no variants- data = {'name': "Testing Class",- 'product_attributes': [color_attribute.pk],- 'variant_attributes': [size_attribute.pk],- 'has_variants': False}+ data = {+ 'name': "Testing Class",+ 'product_attributes': [color_attribute.pk],+ 'variant_attributes': [size_attribute.pk],+ 'has_variants': False}form = ProductClassForm(data)assert not form.is_valid()def test_edit_used_product_class(db):- product_class = ProductClass.objects.create(name='New class',- has_variants=True)+ product_class = ProductClass.objects.create(+ name='New class', has_variants=True)product = Product.objects.create(name='Test product', price=10, product_class=product_class)ProductVariant.objects.create(product=product, sku='1234')@@ -94,17 +98,19 @@ def test_edit_used_product_class(db):# When all products have only one variant you can change# has_variants to falseassert product.variants.all().count() == 1- data = {'name': product_class.name,- 'product_attributes': product_class.product_attributes.all(),- 'variant_attributes': product_class.variant_attributes.all(),- 'has_variants': False}+ data = {+ 'name': product_class.name,+ 'product_attributes': product_class.product_attributes.all(),+ 'variant_attributes': product_class.variant_attributes.all(),+ 'has_variants': False}form = ProductClassForm(data, instance=product_class)assert form.is_valid()- data = {'name': product_class.name,- 'product_attributes': product_class.product_attributes.all(),- 'variant_attributes': product_class.variant_attributes.all(),- 'has_variants': True}+ data = {+ 'name': product_class.name,+ 'product_attributes': product_class.product_attributes.all(),+ 'variant_attributes': product_class.variant_attributes.all(),+ 'has_variants': True}form = ProductClassForm(data, instance=product_class)assert form.is_valid()@@ -112,31 +118,33 @@ def test_edit_used_product_class(db):# has multiple variantsProductVariant.objects.create(product=product, sku='12345')assert product.variants.all().count() == 2- data = {'name': product_class.name,- 'product_attributes': product_class.product_attributes.all(),- 'variant_attributes': product_class.variant_attributes.all(),- 'has_variants': False}+ data = {+ 'name': product_class.name,+ 'product_attributes': product_class.product_attributes.all(),+ 'variant_attributes': product_class.variant_attributes.all(),+ 'has_variants': False}form = ProductClassForm(data, instance=product_class)assert not form.is_valid()assert 'has_variants' in form.errors.keys()-def test_change_attributes_in_product_form(db, product_in_stock,- color_attribute):+def test_change_attributes_in_product_form(+ db, product_in_stock, color_attribute):product = product_in_stockproduct_class = product.product_class- text_attribute = ProductAttribute.objects.create(slug='author',- name='Author')+ text_attribute = ProductAttribute.objects.create(+ slug='author', name='Author')product_class.product_attributes.add(text_attribute)color_value = color_attribute.values.first()new_author = 'Main Tester'new_color = color_value.pk- data = {'name': product.name,- 'price': product.price.gross,- 'categories': [c.pk for c in product.categories.all()],- 'description': 'description',- 'attribute-author': new_author,- 'attribute-color': new_color}+ data = {+ 'name': product.name,+ 'price': product.price.gross,+ 'categories': [c.pk for c in product.categories.all()],+ 'description': 'description',+ 'attribute-author': new_author,+ 'attribute-color': new_color}form = ProductForm(data, instance=product)assert form.is_valid()product = form.save()@@ -145,8 +153,8 @@ def test_change_attributes_in_product_form(db, product_in_stock,def test_get_formfield_name_with_unicode_characters(db):- text_attribute = ProductAttribute.objects.create(slug=u'ąęαβδηθλμπ',- name=u'ąęαβδηθλμπ')+ text_attribute = ProductAttribute.objects.create(+ slug=u'ąęαβδηθλμπ', name=u'ąęαβδηθλμπ')assert text_attribute.get_formfield_name() == 'attribute-ąęαβδηθλμπ'@@ -162,7 +170,8 @@ def test_view_product_toggle_publish(db, admin_client, product_in_stock):assert product.is_published-def test_view_product_not_deleted_before_confirmation(db, admin_client, product_in_stock):+def test_view_product_not_deleted_before_confirmation(+ db, admin_client, product_in_stock):product = product_in_stockurl = reverse('dashboard:product-delete', kwargs={'pk': product.pk})response = admin_client.get(url)@@ -178,9 +187,11 @@ def test_view_product_delete(db, admin_client, product_in_stock):assert not Product.objects.filter(pk=product.pk)-def test_view_product_class_not_deleted_before_confirmation(admin_client, product_in_stock):+def test_view_product_class_not_deleted_before_confirmation(+ admin_client, product_in_stock):product_class = product_in_stock.product_class- url = reverse('dashboard:product-class-delete', kwargs={'pk': product_class.pk})+ url = reverse(+ 'dashboard:product-class-delete', kwargs={'pk': product_class.pk})response = admin_client.get(url)assert response.status_code == HTTP_STATUS_OKassert ProductClass.objects.filter(pk=product_class.pk)@@ -188,17 +199,21 @@ def test_view_product_class_not_deleted_before_confirmation(admin_client, producdef test_view_product_class_delete(db, admin_client, product_in_stock):product_class = product_in_stock.product_class- url = reverse('dashboard:product-class-delete', kwargs={'pk': product_class.pk})+ url = reverse(+ 'dashboard:product-class-delete', kwargs={'pk': product_class.pk})response = admin_client.post(url)assert response.status_code == HTTP_REDIRECTIONassert not ProductClass.objects.filter(pk=product_class.pk)-def test_view_product_variant_not_deleted_before_confirmation(admin_client, product_in_stock):+def test_view_product_variant_not_deleted_before_confirmation(+ admin_client, product_in_stock):product_variant_pk = product_in_stock.variants.first().pk- url = reverse('dashboard:variant-delete',- kwargs={'product_pk':product_in_stock.pk,- 'variant_pk': product_variant_pk})+ url = reverse(+ 'dashboard:variant-delete',+ kwargs={+ 'product_pk': product_in_stock.pk,+ 'variant_pk': product_variant_pk})response = admin_client.get(url)assert response.status_code == HTTP_STATUS_OKassert ProductVariant.objects.filter(pk=product_variant_pk)@@ -206,21 +221,26 @@ def test_view_product_variant_not_deleted_before_confirmation(admin_client, proddef test_view_product_variant_delete(admin_client, product_in_stock):product_variant_pk = product_in_stock.variants.first().pk- url = reverse('dashboard:variant-delete',- kwargs={'product_pk':product_in_stock.pk,- 'variant_pk': product_variant_pk})+ url = reverse(+ 'dashboard:variant-delete',+ kwargs={+ 'product_pk': product_in_stock.pk,+ 'variant_pk': product_variant_pk})response = admin_client.post(url)assert response.status_code == HTTP_REDIRECTIONassert not ProductVariant.objects.filter(pk=product_variant_pk)-def test_view_stock_not_deleted_before_confirmation(admin_client, product_in_stock):+def test_view_stock_not_deleted_before_confirmation(+ admin_client, product_in_stock):product_variant = product_in_stock.variants.first()stock = Stock.objects.filter(variant=product_variant).first()- url = reverse('dashboard:variant-stock-delete',- kwargs={'product_pk':product_in_stock.pk,- 'variant_pk': product_variant.pk,- 'stock_pk': stock.pk})+ url = reverse(+ 'dashboard:variant-stock-delete',+ kwargs={+ 'product_pk': product_in_stock.pk,+ 'variant_pk': product_variant.pk,+ 'stock_pk': stock.pk})response = admin_client.get(url)assert response.status_code == HTTP_STATUS_OKassert Stock.objects.filter(pk=stock.pk)@@ -229,52 +249,63 @@ def test_view_stock_not_deleted_before_confirmation(admin_client, product_in_stodef test_view_stock_delete(admin_client, product_in_stock):product_variant = product_in_stock.variants.first()stock = Stock.objects.filter(variant=product_variant).first()- url = reverse('dashboard:variant-stock-delete',- kwargs={'product_pk':product_in_stock.pk,- 'variant_pk': product_variant.pk,- 'stock_pk': stock.pk})+ url = reverse(+ 'dashboard:variant-stock-delete',+ kwargs={+ 'product_pk': product_in_stock.pk,+ 'variant_pk': product_variant.pk,+ 'stock_pk': stock.pk})response = admin_client.post(url)assert response.status_code == HTTP_REDIRECTIONassert not Stock.objects.filter(pk=stock.pk)-def test_view_stock_location_not_deleted_before_confirmation(admin_client, stock_location):- url = reverse('dashboard:product-stock-location-delete',- kwargs={'location_pk':stock_location.pk})+def test_view_stock_location_not_deleted_before_confirmation(+ admin_client, stock_location):+ url = reverse(+ 'dashboard:product-stock-location-delete',+ kwargs={'location_pk': stock_location.pk})response = admin_client.get(url)assert response.status_code == HTTP_STATUS_OKassert StockLocation.objects.filter(pk=stock_location.pk)def test_view_stock_location_delete(admin_client, stock_location):- url = reverse('dashboard:product-stock-location-delete',- kwargs={'location_pk':stock_location.pk})+ url = reverse(+ 'dashboard:product-stock-location-delete',+ kwargs={'location_pk': stock_location.pk})response = admin_client.post(url)assert response.status_code == HTTP_REDIRECTIONassert not StockLocation.objects.filter(pk=stock_location.pk)-def test_view_attribute_not_deleted_before_confirmation(admin_client, color_attribute):- url = reverse('dashboard:product-attribute-delete',- kwargs={'pk':color_attribute.pk})+def test_view_attribute_not_deleted_before_confirmation(+ admin_client, color_attribute):+ url = reverse(+ 'dashboard:product-attribute-delete',+ kwargs={'pk': color_attribute.pk})response = admin_client.get(url)assert response.status_code == HTTP_STATUS_OKassert ProductAttribute.objects.filter(pk=color_attribute.pk)def test_view_attribute_delete(admin_client, color_attribute):- url = reverse('dashboard:product-attribute-delete',- kwargs={'pk':color_attribute.pk})+ url = reverse(+ 'dashboard:product-attribute-delete',+ kwargs={'pk': color_attribute.pk})response = admin_client.post(url)assert response.status_code == HTTP_REDIRECTIONassert not ProductAttribute.objects.filter(pk=color_attribute.pk)-def test_view_product_image_not_deleted_before_confirmation(admin_client, product_with_image):+def test_view_product_image_not_deleted_before_confirmation(+ admin_client, product_with_image):product_image = product_with_image.images.all()[0]- url = reverse('dashboard:product-image-delete',- kwargs={'img_pk': product_image.pk,- 'product_pk': product_with_image.pk})+ url = reverse(+ 'dashboard:product-image-delete',+ kwargs={+ 'img_pk': product_image.pk,+ 'product_pk': product_with_image.pk})response = admin_client.get(url)assert response.status_code == HTTP_STATUS_OKassert ProductImage.objects.filter(pk=product_image.pk).count()@@ -282,9 +313,11 @@ def test_view_product_image_not_deleted_before_confirmation(admin_client, producdef test_view_product_image_delete(admin_client, product_with_image):product_image = product_with_image.images.all()[0]- url = reverse('dashboard:product-image-delete',- kwargs={'img_pk': product_image.pk,- 'product_pk': product_with_image.pk})+ url = reverse(+ 'dashboard:product-image-delete',+ kwargs={+ 'img_pk': product_image.pk,+ 'product_pk': product_with_image.pk})response = admin_client.post(url)assert response.status_code == HTTP_REDIRECTIONassert not ProductImage.objects.filter(pk=product_image.pk)@@ -323,8 +356,9 @@ def test_view_invalid_reorder_product_images(def test_view_product_image_add(admin_client, product_with_image):assert len(ProductImage.objects.all()) == 1assert len(product_with_image.images.all()) == 1- url = reverse('dashboard:product-image-add',- kwargs={'product_pk': product_with_image.pk})+ url = reverse(+ 'dashboard:product-image-add',+ kwargs={'product_pk': product_with_image.pk})response = admin_client.get(url)assert response.status_code == 200image, image_name = create_image()@@ -343,9 +377,11 @@ def test_view_product_image_edit_same_image_add_description(admin_client, product_with_image):assert len(product_with_image.images.all()) == 1product_image = product_with_image.images.all()[0]- url = reverse('dashboard:product-image-update',- kwargs={'img_pk': product_image.pk,- 'product_pk': product_with_image.pk})+ url = reverse(+ 'dashboard:product-image-update',+ kwargs={+ 'img_pk': product_image.pk,+ 'product_pk': product_with_image.pk})response = admin_client.get(url)assert response.status_code == 200data = {'image_1': ['0.49x0.59'], 'alt': ['description']}@@ -359,9 +395,11 @@ def test_view_product_image_edit_same_image_add_description(def test_view_product_image_edit_new_image(admin_client, product_with_image):assert len(product_with_image.images.all()) == 1product_image = product_with_image.images.all()[0]- url = reverse('dashboard:product-image-update',- kwargs={'img_pk': product_image.pk,- 'product_pk': product_with_image.pk})+ url = reverse(+ 'dashboard:product-image-update',+ kwargs={+ 'img_pk': product_image.pk,+ 'product_pk': product_with_image.pk})response = admin_client.get(url)assert response.status_code == 200image, image_name = create_image()