Skip to content

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

Remove remaining dashboard tests

IKarbowiak952d2b564518
diff --git a/tests/extensions/plugins/test_vatlayer.py b/tests/extensions/plugins/test_vatlayer.py
index fd549dfedf..5f4f15aa71 100644
--- a/tests/extensions/plugins/test_vatlayer.py
+++ b/tests/extensions/plugins/test_vatlayer.py
@@ -1,18 +1,15 @@
from decimal import Decimal
-from unittest import mock
from unittest.mock import Mock
from urllib.parse import urlparse
import pytest
-from django.core.exceptions import ImproperlyConfigured, ValidationError
+from django.core.exceptions import ValidationError
from django.urls import reverse
from django_countries.fields import Country
-from django_prices_vatlayer.models import VAT
from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
from saleor.checkout.utils import add_variant_to_checkout
from saleor.core.taxes import quantize_price
-from saleor.dashboard.taxes.filters import get_country_choices_for_vat
from saleor.extensions.manager import get_extensions_manager
from saleor.extensions.plugins.vatlayer import (
DEFAULT_TAX_RATE_NAME,
@@ -130,137 +127,6 @@ def test_get_taxed_shipping_price(
assert shipping_price == expected_price
-def test_view_taxes_list(admin_client, vatlayer):
- url = reverse("dashboard:taxes")
-
- response = admin_client.get(url)
-
- tax_list = response.context["taxes"].object_list
- assert response.status_code == 200
- assert tax_list == list(VAT.objects.order_by("country_code"))
-
-
-def test_view_tax_details(admin_client, vatlayer):
- tax = VAT.objects.get(country_code="PL")
- tax_rates = [(rate_name, tax["value"]) for rate_name, tax in vatlayer.items()]
- tax_rates = sorted(tax_rates)
- url = reverse("dashboard:tax-details", kwargs={"country_code": "PL"})
-
- response = admin_client.get(url)
- assert response.status_code == 200
- assert response.context["tax"] == tax
- assert response.context["tax_rates"] == tax_rates
-
-
-def test_configure_taxes(admin_client, site_settings):
- url = reverse("dashboard:configure-taxes")
- data = {
- "include_taxes_in_prices": False,
- "display_gross_prices": False,
- "charge_taxes_on_shipping": False,
- }
-
- response = admin_client.post(url, data)
-
- assert response.status_code == 302
- assert get_redirect_location(response) == reverse("dashboard:taxes")
-
- site_settings.refresh_from_db()
- assert not site_settings.include_taxes_in_prices
- assert not site_settings.display_gross_prices
- assert not site_settings.charge_taxes_on_shipping
-
-
[email protected]("saleor.dashboard.taxes.views.messages", create=True)
[email protected]("saleor.dashboard.taxes.views.call_command", create=True)
-def test_fetch_tax_rates(mocked_call_command, mocked_messages, admin_client):
- # Ensure a valid fetch VAT rates request is correctly handled,
- # and is leading to the proper VAT fetching command being invoked.
- url = reverse("dashboard:fetch-tax-rates")
- response = admin_client.post(url)
-
- # Ensure the request was successful
- assert response.status_code == 302
- assert get_redirect_location(response) == reverse("dashboard:taxes")
- assert mocked_messages.success.call_count == 1
-
- # Ensure the get VAT rates (mocked) command was invoked
- mocked_call_command.assert_called_once_with("get_vat_rates")
-
-
[email protected]("saleor.dashboard.taxes.views.messages", create=True)
[email protected]("saleor.dashboard.taxes.views.logger", create=True)
- "saleor.dashboard.taxes.views.call_command",
- side_effect=ImproperlyConfigured("Test"),
- create=True,
-)
-def test_fetch_tax_rates_improperly_configured(
- mocked_call_command, mocked_logger, mocked_messages, admin_client
-):
- # Ensure a failing VAT rate fetching is leading to an error being
- # returned, and that error is handled.
- url = reverse("dashboard:fetch-tax-rates")
- response = admin_client.post(url)
-
- # Ensure the request was successful
- assert response.status_code == 302
- assert get_redirect_location(response) == reverse("dashboard:taxes")
-
- # Ensure error was logged to the logger
- # and the error was returned to the client
- assert mocked_logger.exception.call_count == 1
- assert mocked_messages.warning.call_count == 1
-
- # Ensure the get VAT rates (mocked) command was invoked
- mocked_call_command.assert_called_once_with("get_vat_rates")
-
-
-def test_fetch_tax_rates_invalid_method(admin_client):
- # Ensure the GET method is not allowed for tax rates fetching
- url = reverse("dashboard:fetch-tax-rates")
- assert admin_client.get(url).status_code == 405
-
-
-def test_tax_list_filters_empty(admin_client, vatlayer):
- qs = VAT.objects.order_by("country_code")
- url = reverse("dashboard:taxes")
- data = {"country_code": [""], "sort_by": [""]}
-
- response = admin_client.get(url, data)
-
- assert response.status_code == 200
- assert list(response.context["filter_set"].qs) == list(qs)
-
-
-def test_tax_list_filters_country_code(admin_client, vatlayer):
- qs = VAT.objects.filter(country_code="PL")
- url = reverse("dashboard:taxes")
- data = {"country_code": ["PL"], "sort_by": [""]}
-
- response = admin_client.get(url, data)
-
- assert response.status_code == 200
- assert list(response.context["filter_set"].qs) == list(qs)
-
-
-def test_tax_list_filters_sort_by(admin_client, vatlayer):
- qs = VAT.objects.order_by("-country_code")
- url = reverse("dashboard:taxes")
- data = {"country_code": [""], "sort_by": ["-country_code"]}
-
- response = admin_client.get(url, data)
-
- assert response.status_code == 200
- assert list(response.context["filter_set"].qs) == list(qs)
-
-
-def test_get_country_choices_for_vat(vatlayer):
- expected_choices = [("DE", "Germany"), ("PL", "Poland")]
- choices = get_country_choices_for_vat()
- assert choices == expected_choices
-
-
def test_get_taxes_for_country(vatlayer, compare_taxes):
taxes = get_taxes_for_country(Country("PL"))
compare_taxes(taxes, vatlayer)
diff --git a/tests/test_elasticsearch.py b/tests/test_elasticsearch.py
index 9ea2399942..a17f206893 100644
--- a/tests/test_elasticsearch.py
+++ b/tests/test_elasticsearch.py
@@ -3,8 +3,6 @@ from django.urls import reverse
from elasticsearch_dsl.connections import connections
from prices import Money
-from saleor.account.models import User
-from saleor.order.models import Order
from saleor.product.models import Product
MATCH_SEARCH_REQUEST = ["method", "host", "port", "path"]
@@ -97,114 +95,3 @@ def test_new_search_doesnt_show_unpublished(db, products_with_mixed_publishing,
published_products = STOREFRONT_PRODUCTS - PRODUCTS_TO_UNPUBLISH
found_products = execute_search(client, PHRASE_WITH_RESULTS)
assert published_products == set(found_products)
-
-
-def execute_dashboard_search(client, phrase):
- response = client.get(reverse("dashboard:search"), {"q": phrase})
- assert phrase == response.context["query"]
- found_prod = {p.pk for p in response.context["products"]}
- found_users = {p.pk for p in response.context["users"]}
- found_orders = {p.pk for p in response.context["orders"]}
- return found_prod, found_users, found_orders
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_with_empty_results(db, admin_client):
- products, users, orders = execute_dashboard_search(
- admin_client, PHRASE_WITHOUT_RESULTS
- )
- assert 0 == len(products)
- assert 0 == len(users)
- assert 0 == len(orders)
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_with_product_result(db, indexed_products, admin_client):
- products, _, _ = execute_dashboard_search(admin_client, PHRASE_WITH_RESULTS)
- assert DASHBOARD_PRODUCTS == products
-
-
-# data below must be aligned with recorded communication every time
-EXISTING_EMAIL = "[email protected]"
-NON_EXISTING_EMAIL = "[email protected]"
-USER_EMAIL_WITH_ORDER = "[email protected]"
-USER_NAME_WITH_ORDER = "Martin"
-USER_EMAIL_WITH_ORDER_WITHOUT_ADDRES = "[email protected]"
-USER_NAME_WITH_ORDER_WITHOUT_ADDRES = "Rachel"
-EXISTING_NAME = "Rhonda"
-EXISTING_NAME_FULL = "[email protected]"
-EXISTING_NAME_WITHOUT_ADDRESS = "Brett"
-EXISTING_NAME_FULL_WITHOUT_ADDRESS = "[email protected]"
-USERS = {
- EXISTING_EMAIL: 109,
- NON_EXISTING_EMAIL: 870,
- USER_EMAIL_WITH_ORDER: 102,
- USER_EMAIL_WITH_ORDER_WITHOUT_ADDRES: 117,
- EXISTING_NAME_FULL: 106,
- EXISTING_NAME_FULL_WITHOUT_ADDRESS: 122,
-}
-ORDERS = {USER_EMAIL_WITH_ORDER: {11, 17}, USER_EMAIL_WITH_ORDER_WITHOUT_ADDRES: {15}}
-
-
-def customers(db):
- for email, pk in USERS.items():
- User.objects.create_user(email, "password", pk=pk)
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_user_by_email(db, admin_client, customers):
- _, users, _ = execute_dashboard_search(admin_client, EXISTING_EMAIL)
- assert {USERS[EXISTING_EMAIL]} == users
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_user_name(db, admin_client, customers):
- _, users, _ = execute_dashboard_search(admin_client, EXISTING_NAME)
- assert USERS[EXISTING_NAME_FULL] in users
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_user_name_without_address(db, admin_client, customers):
- _, users, _ = execute_dashboard_search(admin_client, EXISTING_NAME_WITHOUT_ADDRESS)
- assert USERS[EXISTING_NAME_FULL_WITHOUT_ADDRESS] in users
-
-
-def orders(db, address):
- all_pks = set()
- for email, pks in ORDERS.items():
- for pk in pks:
- Order.objects.create(billing_address=address, user_email=email, pk=pk)
- all_pks = all_pks | pks
- return all_pks
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_orders_by_user_email(db, admin_client, customers, orders):
- _, _, orders = execute_dashboard_search(admin_client, USER_EMAIL_WITH_ORDER)
- assert ORDERS[USER_EMAIL_WITH_ORDER] == orders
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_orders_by_user_name(db, admin_client, customers, orders):
- _, _, orders = execute_dashboard_search(admin_client, USER_NAME_WITH_ORDER)
- assert ORDERS[USER_EMAIL_WITH_ORDER] == orders
-
-
[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)
-def test_dashboard_search_orders_by_user_name_without_address(
- db, admin_client, customers, orders
-):
- _, _, orders = execute_dashboard_search(
- admin_client, USER_NAME_WITH_ORDER_WITHOUT_ADDRES
- )
- assert ORDERS[USER_EMAIL_WITH_ORDER_WITHOUT_ADDRES] == orders
diff --git a/tests/test_product_minimal_variant_price.py b/tests/test_product_minimal_variant_price.py
index 1a44cd7b40..731d8e2cf9 100644
--- a/tests/test_product_minimal_variant_price.py
+++ b/tests/test_product_minimal_variant_price.py
@@ -1,11 +1,8 @@
-from decimal import Decimal
from unittest.mock import patch
from django.core.management import call_command
-from django.urls import reverse
from prices import Money
-from saleor.discount import DiscountValueType
from saleor.product.models import Product, ProductVariant
from saleor.product.tasks import (
update_all_products_minimal_variant_prices_task,
@@ -196,135 +193,6 @@ def test_product_variant_objects_bulk_create_updates_minimal_variant_price(produ
assert product.minimal_variant_price == Money("1.00", "USD")
-def test_dashboard_product_create_view_sets_minimal_variant_price(
- admin_client, product_type, category
-):
- url = reverse("dashboard:product-add", kwargs={"type_pk": product_type.pk})
- data = {
- "name": "Product name",
- "description": "Description.",
- "price_0": "9.99",
- "price_1": "USD",
- "category": category.pk,
- }
-
- response = admin_client.post(url, data)
- assert response.status_code == 302
- assert Product.objects.count() == 1
- product = Product.objects.get()
- assert product.minimal_variant_price == product.price == Money("9.99", "USD")
-
-
-def test_dashboard_product_variant_create_view_updates_minimal_variant_price(
- admin_client, product
-):
- url = reverse("dashboard:variant-add", kwargs={"product_pk": product.pk})
- data = {
- "sku": "ACME/1/2/3",
- "price_override_0": "4.99",
- "price_override_1": product.currency,
- "quantity": 1,
- }
-
- response = admin_client.post(url, data)
- assert response.status_code == 302
-
- product.refresh_from_db()
-
- assert product.variants.count() == 2
- assert product.minimal_variant_price != product.price
- assert product.minimal_variant_price == Money("4.99", "USD")
-
-
-def test_dashboard_product_variant_delete_view_updates_minimal_variant_price(
- admin_client, product
-):
- # Set "price_override" on the variant to lower the "minimal_variant_price"
- assert product.minimal_variant_price == product.price == Money("10", "USD")
- variant = product.variants.get()
- variant.price_override = Money("4.99", "USD")
- variant.save()
- update_product_minimal_variant_price(product)
- product.refresh_from_db()
- assert product.minimal_variant_price == variant.price_override
-
- url = reverse(
- "dashboard:variant-delete",
- kwargs={"product_pk": product.pk, "variant_pk": variant.pk},
- )
-
- response = admin_client.post(url)
- assert response.status_code == 302
-
- product.refresh_from_db()
- assert product.minimal_variant_price == product.price
-
-
-def test_dashboard_sale_of_product_create_view_updates_minimal_variant_price(
- admin_client, product
-):
- # Store the old "minimal_variant_price"
- old_minimal_variant_price = product.minimal_variant_price
- # Create the "Sale" object of the given product
- url = reverse("dashboard:sale-add")
- data = {
- "name": "Half price products",
- "type": DiscountValueType.PERCENTAGE,
- "value": "50",
- "start_date": "2019-07-11 00:00:01",
- "products": [product.pk],
- }
- response = admin_client.post(url, data)
- assert response.status_code == 302
-
- product.refresh_from_db()
- assert product.minimal_variant_price == Decimal("0.5") * old_minimal_variant_price
-
-
-def test_dashboard_sale_of_category_create_view_updates_minimal_variant_price(
- admin_client, product
-):
- category = product.category
- # Store the old "minimal_variant_price"
- old_minimal_variant_price = product.minimal_variant_price
- # Create the "Sale" object of the given category
- url = reverse("dashboard:sale-add")
- data = {
- "name": "Half price category",
- "type": DiscountValueType.PERCENTAGE,
- "value": "50",
- "start_date": "2019-07-11 00:00:01",
- "categories": [category.pk],
- }
- response = admin_client.post(url, data)
- assert response.status_code == 302
-
- product.refresh_from_db()
- assert product.minimal_variant_price == Decimal("0.5") * old_minimal_variant_price
-
-
-def test_dashboard_sale_of_collection_create_view_updates_minimal_variant_price(
- admin_client, product, collection
-):
- collection.products.add(product)
- # Store the old "minimal_variant_price"
- old_minimal_variant_price = product.minimal_variant_price
- # Create the "Sale" object of the given collection
- url = reverse("dashboard:sale-add")
- data = {
- "name": "Half price collection",
- "type": DiscountValueType.PERCENTAGE,
- "value": "50",
- "start_date": "2019-07-11 00:00:01",
- "collections": [collection.pk],
- }
- response = admin_client.post(url, data)
- assert response.status_code == 302
-
- product.refresh_from_db()
- assert product.minimal_variant_price == Decimal("0.5") * old_minimal_variant_price
-
-
@patch(
"saleor.product.management.commands"
".update_all_products_minimal_variant_prices"