Skip to content

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

Fix misplaced dashboard tests and removed duplicate tests

NyanKiyoshi5d4df35c8c80
diff --git a/tests/dashboard/test_customer.py b/tests/dashboard/test_customer.py
index c0fb17984f..475254a5f4 100644
--- a/tests/dashboard/test_customer.py
+++ b/tests/dashboard/test_customer.py
@@ -1,8 +1,22 @@
+import json
+
from django.urls import reverse
from saleor.account.models import CustomerNote, User
-from saleor.dashboard.customer.forms import (
- CustomerDeleteForm, CustomerNoteForm)
+from saleor.dashboard.customer.forms import CustomerDeleteForm, CustomerNoteForm
+
+
+def test_ajax_users_list(admin_client, admin_user, customer_user):
+ users_list = [
+ {'id': admin_user.pk, 'text': admin_user.get_ajax_label()},
+ {'id': customer_user.pk, 'text': customer_user.get_ajax_label()}]
+ url = reverse('dashboard:ajax-users-list')
+
+ response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+ resp_decoded = json.loads(response.content.decode('utf-8'))
+
+ assert response.status_code == 200
+ assert resp_decoded == {'results': users_list}
def test_add_note_to_customer(admin_user, customer_user):
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 17a962a2d9..180a436bda 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -1,3 +1,4 @@
+import json
from unittest.mock import Mock
import pytest
@@ -20,6 +21,39 @@ from saleor.order.utils import add_variant_to_order, change_order_line_quantity
from saleor.product.models import ProductVariant
+def test_ajax_order_shipping_methods_list(
+ admin_client, order, shipping_method):
+ method = shipping_method.price_per_country.get()
+ shipping_methods_list = [
+ {'id': method.pk, 'text': method.get_ajax_label()}]
+ url = reverse(
+ 'dashboard:ajax-order-shipping-methods', kwargs={'order_pk': order.pk})
+
+ response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+ resp_decoded = json.loads(response.content.decode('utf-8'))
+
+ assert response.status_code == 200
+ assert resp_decoded == {'results': shipping_methods_list}
+
+
+def test_ajax_order_shipping_methods_list_different_country(
+ admin_client, order, shipping_method):
+ order.shipping_address = order.billing_address.get_copy()
+ order.save()
+ method = shipping_method.price_per_country.get()
+ shipping_methods_list = [
+ {'id': method.pk, 'text': method.get_ajax_label()}]
+ shipping_method.price_per_country.create(price=15, country_code='DE')
+ url = reverse(
+ 'dashboard:ajax-order-shipping-methods', kwargs={'order_pk': order.pk})
+
+ response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+ resp_decoded = json.loads(response.content.decode('utf-8'))
+
+ assert response.status_code == 200
+ assert resp_decoded == {'results': shipping_methods_list}
+
+
@pytest.mark.integration
def test_view_capture_order_payment_preauth(
admin_client, order_with_lines, payment_preauth):
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
index 2c1ce7edee..6fccc95c05 100644
--- a/tests/dashboard/test_product.py
+++ b/tests/dashboard/test_product.py
@@ -1,12 +1,10 @@
import json
-from io import BytesIO
-from unittest.mock import MagicMock, Mock, patch
+from unittest.mock import MagicMock, Mock
from django.conf import settings
from django.forms import HiddenInput
from django.forms.models import model_to_dict
from django.urls import reverse
-from PIL import Image
from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
from tests.utils import get_redirect_location
@@ -16,6 +14,7 @@ from saleor.product.forms import VariantChoiceField
from saleor.product.models import (
AttributeChoiceValue, Collection, Product, ProductAttribute, ProductImage,
ProductType, ProductVariant)
+
from ..utils import create_image
@@ -260,19 +259,6 @@ def test_view_product_bulk_update_unpublish(admin_client, product_list):
assert not p.is_published
-def test_product_variant_form(product):
- variant = product.variants.first()
- variant.name = ''
- variant.save()
- example_size = 'Small Size'
- data = {'attribute-size': example_size, 'sku': '1111', 'quantity': 2}
- form = ProductVariantForm(data, instance=variant)
- assert form.is_valid()
- form.save()
- variant.refresh_from_db()
- assert variant.name == example_size
-
-
def test_view_ajax_products_list(admin_client, product):
url = reverse('dashboard:ajax-products')
diff --git a/tests/test_account.py b/tests/test_account.py
index 3edc6f3e3b..b18ad001ab 100644
--- a/tests/test_account.py
+++ b/tests/test_account.py
@@ -1,4 +1,3 @@
-import json
import os
import uuid
from unittest.mock import patch
@@ -214,19 +213,6 @@ def test_user_ajax_label_without_address(admin_user):
assert admin_user.get_ajax_label() == admin_user.email
-def test_ajax_users_list(admin_client, admin_user, customer_user):
- users_list = [
- {'id': admin_user.pk, 'text': admin_user.get_ajax_label()},
- {'id': customer_user.pk, 'text': customer_user.get_ajax_label()}]
- url = reverse('dashboard:ajax-users-list')
-
- response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
- resp_decoded = json.loads(response.content.decode('utf-8'))
-
- assert response.status_code == 200
- assert resp_decoded == {'results': users_list}
-
-
def test_disabled_recaptcha():
"""
This test creates a new form that should not contain any recaptcha field.
diff --git a/tests/test_order.py b/tests/test_order.py
index 3b57b3b885..cea2cf6be6 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -1,4 +1,3 @@
-import json
from decimal import Decimal
import pytest
@@ -353,39 +352,6 @@ def test_order_queryset_to_ship():
assert all([order not in orders for order in orders_not_to_ship])
-def test_ajax_order_shipping_methods_list(
- admin_client, order, shipping_method):
- method = shipping_method.price_per_country.get()
- shipping_methods_list = [
- {'id': method.pk, 'text': method.get_ajax_label()}]
- url = reverse(
- 'dashboard:ajax-order-shipping-methods', kwargs={'order_pk': order.pk})
-
- response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
- resp_decoded = json.loads(response.content.decode('utf-8'))
-
- assert response.status_code == 200
- assert resp_decoded == {'results': shipping_methods_list}
-
-
-def test_ajax_order_shipping_methods_list_different_country(
- admin_client, order, shipping_method):
- order.shipping_address = order.billing_address.get_copy()
- order.save()
- method = shipping_method.price_per_country.get()
- shipping_methods_list = [
- {'id': method.pk, 'text': method.get_ajax_label()}]
- shipping_method.price_per_country.create(price=15, country_code='DE')
- url = reverse(
- 'dashboard:ajax-order-shipping-methods', kwargs={'order_pk': order.pk})
-
- response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
- resp_decoded = json.loads(response.content.decode('utf-8'))
-
- assert response.status_code == 200
- assert resp_decoded == {'results': shipping_methods_list}
-
-
def test_update_order_prices(order_with_lines):
taxes = get_taxes_for_country(Country('DE'))
address = order_with_lines.shipping_address
diff --git a/tests/test_product.py b/tests/test_product.py
index f49dae5c50..901bff37e6 100644
--- a/tests/test_product.py
+++ b/tests/test_product.py
@@ -1,5 +1,4 @@
import datetime
-import json
from unittest.mock import patch
import pytest
@@ -388,30 +387,6 @@ def test_get_variant_picker_data_proper_variant_count(product):
assert len(data['variantAttributes'][0]['values']) == 1
-def test_view_ajax_available_variants_list(admin_client, product):
- variant = product.variants.first()
- variant_list = [
- {'id': variant.pk, 'text': '123, Test product (123), $10.00'}]
- url = reverse('dashboard:ajax-available-variants')
-
- response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
-
- resp_decoded = json.loads(response.content.decode('utf-8'))
- assert response.status_code == 200
- assert resp_decoded == {'results': variant_list}
-
-
-def test_view_ajax_available_products_list(admin_client, product):
- product_list = [{'id': product.pk, 'text': 'Test product'}]
- url = reverse('dashboard:ajax-products')
-
- response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
-
- resp_decoded = json.loads(response.content.decode('utf-8'))
- assert response.status_code == 200
- assert resp_decoded == {'results': product_list}
-
-
def test_render_product_page_with_no_variant(
unavailable_product, admin_client):
product = unavailable_product