Skip to content

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

Do not remove tests for deprecated files

Mira Szewczyk8b60494087ad
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 51a8ce8313..e33649918a 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -22,6 +22,7 @@ from ....product.utils.availability import (
from ....product.utils.costs import get_margin_for_variant, get_product_costs_data
from ....stock import models as stock_models
from ....stock.availability import (
+ get_available_quantity,
get_available_quantity_for_customer,
is_product_in_stock,
is_variant_in_stock,
@@ -301,7 +302,12 @@ class ProductVariant(CountableDjangoObjectType, MetadataObjectType):
@staticmethod
def resolve_stock_quantity(root: models.ProductVariant, info):
country = info.context.country
- stock = stock_models.Stock.objects.get_variant_stock_for_country(country, root)
+ try:
+ stock = stock_models.Stock.objects.get_variant_stock_for_country(
+ country, root
+ )
+ except stock_models.Stock.DoesNotExist:
+ return 0
return get_available_quantity_for_customer(stock)
@staticmethod
@@ -355,9 +361,7 @@ class ProductVariant(CountableDjangoObjectType, MetadataObjectType):
@staticmethod
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
def resolve_quantity(root: models.ProductVariant, info):
- country = info.context.country
- stock = stock_models.Stock.objects.get_variant_stock_for_country(country, root)
- return stock.quantity
+ return get_available_quantity(root, info.context.country)
@staticmethod
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
diff --git a/tests/api/benchmark/test_product.py b/tests/api/benchmark/test_product.py
index 14e6580373..13bd2d6d98 100644
--- a/tests/api/benchmark/test_product.py
+++ b/tests/api/benchmark/test_product.py
@@ -24,6 +24,8 @@ def test_product_details(product, api_client, count_queries):
id
sku
name
+ stockQuantity
+ isAvailable
pricing {
discountLocalCurrency {
currency
diff --git a/tests/api/benchmark/test_variant.py b/tests/api/benchmark/test_variant.py
index 23980bee3b..aa904e974d 100644
--- a/tests/api/benchmark/test_variant.py
+++ b/tests/api/benchmark/test_variant.py
@@ -4,12 +4,15 @@ import graphene
import pytest
from saleor.product.models import ProductVariant
+from saleor.stock.models import Stock
from tests.api.utils import get_graphql_content
@pytest.mark.django_db
@pytest.mark.count_queries(autouse=False)
-def test_retrieve_variant_list(product_variant_list, api_client, count_queries):
+def test_retrieve_variant_list(
+ product_variant_list, api_client, count_queries, warehouse
+):
query = """
fragment BasicProductFields on Product {
id
@@ -27,6 +30,8 @@ def test_retrieve_variant_list(product_variant_list, api_client, count_queries):
id
sku
name
+ stockQuantity
+ isAvailable
pricing {
discountLocalCurrency {
currency
@@ -75,6 +80,7 @@ def test_retrieve_variant_list(product_variant_list, api_client, count_queries):
edges {
node {
...ProductVariantFields
+ stockQuantity
product {
...BasicProductFields
}
@@ -83,7 +89,12 @@ def test_retrieve_variant_list(product_variant_list, api_client, count_queries):
}
}
"""
-
+ Stock.objects.bulk_create(
+ [
+ Stock(product_variant=variant, warehouse=warehouse)
+ for variant in product_variant_list
+ ]
+ )
variables = {
"ids": [
graphene.Node.to_global_id("ProductVariant", variant.pk)
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 23e43c1dc8..e5068ee783 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -897,6 +897,7 @@ QUERY_CREATE_PRODUCT_WITHOUT_VARIANTS = """
id
sku
trackInventory
+ quantity
}
category {
name
diff --git a/tests/api/test_variant_pricing.py b/tests/api/test_variant_pricing.py
index 42f3667c18..7b05d125e3 100644
--- a/tests/api/test_variant_pricing.py
+++ b/tests/api/test_variant_pricing.py
@@ -13,6 +13,7 @@ query {
edges {
node {
variants {
+ isAvailable
pricing {
onSale
@@ -116,7 +117,7 @@ def test_variant_pricing(variant: ProductVariant, monkeypatch, settings, stock):
settings.OPENEXCHANGERATES_API_KEY = "fake-key"
pricing = get_variant_availability(variant, local_currency="PLN", country="US")
- assert pricing.price_local_currency.currency == "PLN"
+ assert pricing.price_local_currency.currency == "PLN" # type: ignore
pricing = get_variant_availability(variant)
assert pricing.price.tax.amount
diff --git a/tests/test_emails.py b/tests/test_emails.py
index 9f7bc76b21..0ed80b1683 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -154,6 +154,7 @@ def test_send_confirmation_emails_without_addresses_for_payment(
add_variant_to_order(order, digital_content.product_variant, quantity=1)
order.shipping_address = None
order.shipping_method = None
+ order.billing_address = None
order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])
emails.send_payment_confirmation(order.pk)