Skip to content

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

Style fixes

Michał Jeloneke7ad42980b3f
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index 1e5f512e09..dc6d1c012d 100644
--- a/saleor/checkout/models.py
+++ b/saleor/checkout/models.py
@@ -138,8 +138,7 @@ class CartLine(models.Model):
return NotImplemented
return (
- self.variant == other.variant and
- self.quantity == other.quantity)
+ self.variant == other.variant and self.quantity == other.quantity)
def __ne__(self, other):
return not self == other # pragma: no cover
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index b7f798c8b6..6484615352 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -1,6 +1,4 @@
import graphene
-from django.core.exceptions import ValidationError
-from django.core.validators import validate_email
from django.db import transaction
from ...checkout import models
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index edcf312dc4..9c852ca1e1 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -39,8 +39,7 @@ def test_checkout_create(api_client, variant, graphql_address_data):
'email': test_email,
'shippingAddress': shipping_address}}
assert not Cart.objects.exists()
- response = api_client.post_graphql(
- MUTATION_CHECKOUT_CREATE, variables)
+ response = api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)
content = get_graphql_content(response)
new_cart = Cart.objects.first()
@@ -74,8 +73,7 @@ def test_checkout_create_required_email(api_client, variant):
'variantId': variant_id}],
'email': ''}}
- response = api_client.post_graphql(
- MUTATION_CHECKOUT_CREATE, variables)
+ response = api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)
content = get_graphql_content(response)
errors = content['data']['checkoutCreate']['errors']
@@ -84,8 +82,7 @@ def test_checkout_create_required_email(api_client, variant):
assert errors[0]['message'] == 'This field cannot be blank.'
-def test_checkout_create_logged_in_customer(
- user_api_client, variant):
+def test_checkout_create_logged_in_customer(user_api_client, variant):
variant_id = graphene.Node.to_global_id('ProductVariant', variant.id)
variables = {
'checkoutInput': {
@@ -158,9 +155,12 @@ def test_checkout_create_logged_in_customer_custom_addresses(
cart_user = new_cart.user
customer = user_api_client.user
assert customer.id == cart_user.id
- assert not customer.default_shipping_address_id == new_cart.shipping_address_id
- assert not customer.default_billing_address_id == new_cart.billing_address_id
- assert new_cart.shipping_address.first_name == shipping_address['firstName']
+ assert not (
+ customer.default_shipping_address_id == new_cart.shipping_address_id)
+ assert not (
+ customer.default_billing_address_id == new_cart.billing_address_id)
+ assert new_cart.shipping_address.first_name == shipping_address[
+ 'firstName']
assert new_cart.billing_address.first_name == billing_address['firstName']
@@ -181,7 +181,8 @@ def test_checkout_create_check_lines_quantity(
MUTATION_CHECKOUT_CREATE, variables)
content = get_graphql_content(response)
data = content['data']['checkoutCreate']
- assert data['errors'][0]['message'] == 'Could not add item Test product (SKU_A). Only 2 remaining in stock.'
+ assert data['errors'][0]['message'] == (
+ 'Could not add item Test product (SKU_A). Only 2 remaining in stock.')
assert data['errors'][0]['field'] == 'quantity'
@@ -199,12 +200,14 @@ def test_checkout_available_payment_gateways(
content = get_graphql_content(response)
data = content['data']['checkout']
checkout_payment_gateways = [
- str_to_enum(gateway) for gateway in settings.CHECKOUT_PAYMENT_GATEWAYS.keys()]
+ str_to_enum(gateway)
+ for gateway in settings.CHECKOUT_PAYMENT_GATEWAYS.keys()]
assert data['availablePaymentGateways'] == checkout_payment_gateways
MUTATION_CHECKOUT_LINES_ADD = """
- mutation checkoutLinesAdd($checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
+ mutation checkoutLinesAdd(
+ $checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
checkoutLinesAdd(checkoutId: $checkoutId, lines: $lines) {
checkout {
token
@@ -232,7 +235,9 @@ def test_checkout_lines_add(user_api_client, cart_with_item, variant):
variables = {
'checkoutId': checkout_id,
- 'lines': [{'variantId': variant_id, 'quantity': 1}]}
+ 'lines': [{
+ 'variantId': variant_id,
+ 'quantity': 1}]}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_LINES_ADD, variables)
content = get_graphql_content(response)
@@ -244,14 +249,15 @@ def test_checkout_lines_add(user_api_client, cart_with_item, variant):
assert line.quantity == 1
-def test_checkout_lines_add_empty_checkout(
- user_api_client, cart, variant):
+def test_checkout_lines_add_empty_checkout(user_api_client, cart, variant):
variant_id = graphene.Node.to_global_id('ProductVariant', variant.pk)
checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)
variables = {
'checkoutId': checkout_id,
- 'lines': [{'variantId': variant_id, 'quantity': 1}]}
+ 'lines': [{
+ 'variantId': variant_id,
+ 'quantity': 1}]}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_LINES_ADD, variables)
content = get_graphql_content(response)
@@ -270,37 +276,44 @@ def test_checkout_lines_add_check_lines_quantity(
variables = {
'checkoutId': checkout_id,
- 'lines': [{'variantId': variant_id, 'quantity': 3}]}
+ 'lines': [{
+ 'variantId': variant_id,
+ 'quantity': 3}]}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_LINES_ADD, variables)
content = get_graphql_content(response)
data = content['data']['checkoutLinesAdd']
- assert data['errors'][0]['message'] == 'Could not add item Test product (SKU_A). Only 2 remaining in stock.'
+ assert data['errors'][0]['message'] == (
+ 'Could not add item Test product (SKU_A). Only 2 remaining in stock.')
assert data['errors'][0]['field'] == 'quantity'
-def test_checkout_lines_invalid_variant_id(
- user_api_client, cart, variant):
+def test_checkout_lines_invalid_variant_id(user_api_client, cart, variant):
variant_id = graphene.Node.to_global_id('ProductVariant', variant.pk)
invalid_variant_id = 'InvalidId'
checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)
variables = {
- 'checkoutId': checkout_id,
- 'lines': [
- {'variantId': variant_id, 'quantity': 1},
- {'variantId': invalid_variant_id, 'quantity': 3}]}
+ 'checkoutId':
+ checkout_id,
+ 'lines': [{
+ 'variantId': variant_id,
+ 'quantity': 1}, {
+ 'variantId': invalid_variant_id,
+ 'quantity': 3}]}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_LINES_ADD, variables)
content = get_graphql_content(response)
data = content['data']['checkoutLinesAdd']
- error_msg = "Could not resolve to a nodes with the global id list of '%s'." % [invalid_variant_id]
- assert data['errors'][0]['message'] == error_msg
+ error_msg = (
+ 'Could not resolve to a nodes with the global id list of \'%s\'.')
+ assert data['errors'][0]['message'] == error_msg % [invalid_variant_id]
assert data['errors'][0]['field'] == 'variantId'
MUTATION_CHECKOUT_LINES_UPDATE = """
- mutation checkoutLinesUpdate($checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
+ mutation checkoutLinesUpdate(
+ $checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lines) {
checkout {
token
@@ -348,8 +361,7 @@ def test_checkout_lines_update(user_api_client, cart_with_item):
assert line.quantity == 1
-def test_checkout_lines_update_invalid_checkout_id(
- user_api_client):
+def test_checkout_lines_update_invalid_checkout_id(user_api_client):
variables = {'checkoutId': 'test', 'lines': []}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -377,7 +389,8 @@ def test_checkout_lines_update_check_lines_quantity(
content = get_graphql_content(response)
data = content['data']['checkoutLinesUpdate']
- assert data['errors'][0]['message'] == 'Could not add item Test product (123). Only 9 remaining in stock.'
+ assert data['errors'][0]['message'] == (
+ 'Could not add item Test product (123). Only 9 remaining in stock.')
assert data['errors'][0]['field'] == 'quantity'
@@ -425,7 +438,8 @@ def test_checkout_customer_attach(
query = """
mutation checkoutCustomerAttach($checkoutId: ID!, $customerId: ID!) {
- checkoutCustomerAttach(checkoutId: $checkoutId, customerId: $customerId) {
+ checkoutCustomerAttach(
+ checkoutId: $checkoutId, customerId: $customerId) {
checkout {
token
}
@@ -494,12 +508,15 @@ def test_checkout_customer_detach_without_customer(
MUTATION_CHECKOUT_CUSTOMER_DETACH, variables)
content = get_graphql_content(response)
data = content['data']['checkoutCustomerDetach']
- assert data['errors'][0]['message'] == 'There\'s no customer assigned to this Checkout.'
+ assert data['errors'][0][
+ 'message'] == 'There\'s no customer assigned to this Checkout.'
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE = """
- mutation checkoutShippingAddressUpdate($checkoutId: ID!, $shippingAddress: AddressInput!) {
- checkoutShippingAddressUpdate(checkoutId: $checkoutId, shippingAddress: $shippingAddress) {
+ mutation checkoutShippingAddressUpdate(
+ $checkoutId: ID!, $shippingAddress: AddressInput!) {
+ checkoutShippingAddressUpdate(
+ checkoutId: $checkoutId, shippingAddress: $shippingAddress) {
checkout {
token,
id
@@ -520,7 +537,8 @@ def test_checkout_shipping_address_update(
shipping_address = graphql_address_data
variables = {
- 'checkoutId': checkout_id, 'shippingAddress': shipping_address}
+ 'checkoutId': checkout_id,
+ 'shippingAddress': shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables)
@@ -549,7 +567,8 @@ def test_checkout_shipping_address_update_invalid_country_code(
shipping_address = graphql_address_data
shipping_address['country'] = 'CODE'
variables = {
- 'checkoutId': checkout_id, 'shippingAddress': shipping_address}
+ 'checkoutId': checkout_id,
+ 'shippingAddress': shipping_address}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables)
@@ -566,8 +585,10 @@ def test_checkout_billing_address_update(
checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)
query = """
- mutation checkoutBillingAddressUpdate($checkoutId: ID!, $billingAddress: AddressInput!) {
- checkoutBillingAddressUpdate(checkoutId: $checkoutId, billingAddress: $billingAddress) {
+ mutation checkoutBillingAddressUpdate(
+ $checkoutId: ID!, $billingAddress: AddressInput!) {
+ checkoutBillingAddressUpdate(
+ checkoutId: $checkoutId, billingAddress: $billingAddress) {
checkout {
token,
id
@@ -615,6 +636,7 @@ CHECKOUT_EMAIL_UPDATE_MUTATION = """
}
"""
+
def test_checkout_email_update(user_api_client, cart_with_item):
cart = cart_with_item
assert not cart.email
@@ -719,8 +741,7 @@ def test_checkout_complete_invalid_checkout_id(user_api_client):
def test_checkout_complete_no_payment(
- user_api_client, cart_with_item, address,
- shipping_method):
+ user_api_client, cart_with_item, address, shipping_method):
checkout = cart_with_item
checkout.shipping_address = address
checkout.shipping_method = shipping_method
@@ -846,10 +867,11 @@ def test_checkout_prices(user_api_client, cart_with_item):
@patch('saleor.graphql.checkout.mutations.clean_shipping_method')
def test_checkout_shipping_method_update(
- mock_clean_shipping, staff_api_client, shipping_method,
- cart_with_item, sale, vatlayer):
+ mock_clean_shipping, staff_api_client, shipping_method, cart_with_item,
+ sale, vatlayer):
query = """
- mutation checkoutShippingMethodUpdate($checkoutId:ID!, $shippingMethodId:ID!){
+ mutation checkoutShippingMethodUpdate(
+ $checkoutId:ID!, $shippingMethodId:ID!){
checkoutShippingMethodUpdate(
checkoutId:$checkoutId, shippingMethodId:$shippingMethodId) {
errors {
@@ -962,8 +984,7 @@ def test_ready_to_place_order(
assert not error
-def test_checkout_complete_no_shipping_method(
- cart_with_item, address):
+def test_ready_to_place_order_no_shipping_method(cart_with_item, address):
checkout = cart_with_item
checkout.shipping_address = address
checkout.save()
@@ -972,7 +993,7 @@ def test_checkout_complete_no_shipping_method(
assert error == 'Shipping method is not set'
-def test_checkout_complete_no_shipping_addres(
+def test_ready_to_place_order_no_shipping_address(
cart_with_item, shipping_method):
checkout = cart_with_item
checkout.shipping_method = shipping_method
@@ -982,7 +1003,7 @@ def test_checkout_complete_no_shipping_addres(
assert error == 'Shipping address is not set'
-def test_checkout_complete_invalid_shipping_method(
+def test_ready_to_place_order_invalid_shipping_method(
cart_with_item, address, shipping_zone_without_countries):
checkout = cart_with_item
checkout.shipping_address = address
@@ -994,7 +1015,7 @@ def test_checkout_complete_invalid_shipping_method(
assert error == 'Shipping method is not valid for your shipping address'
-def test_checkout_complete_no_payment(
+def test_ready_to_place_order_no_payment(
cart_with_item, shipping_method, address):
checkout = cart_with_item
checkout.shipping_address = address