Skip to content

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

cleaning code after review

Maciek Jabłońskieaa8c5d1bece
diff --git a/saleor/order/models.py b/saleor/order/models.py
index e47d487a2d..a484691c14 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -108,6 +108,12 @@ class Order(models.Model, ItemSet):
total = self.get_total()
return total_paid >= total.gross
+ def get_user_current_email(self):
+ if self.user:
+ return self.user.email
+ else:
+ return self.user_email
+
def __iter__(self):
return iter(self.groups.all())
@@ -137,7 +143,7 @@ class Order(models.Model, ItemSet):
Price(0, currency=settings.DEFAULT_CURRENCY))
def send_confirmation_email(self):
- email = self.user_email
+ email = self.get_user_current_email()
payment_url = build_absolute_uri(
reverse('order:details', kwargs={'token': self.token}))
context = {'payment_url': payment_url}
@@ -369,7 +375,7 @@ class Payment(BasePayment):
reverse('order:details', kwargs={'token': self.order.token}))
def send_confirmation_email(self):
- email = self.order.user_email
+ email = self.order.get_user_current_email()
order_url = build_absolute_uri(
reverse('order:details', kwargs={'token': self.order.token}))
context = {'order_url': order_url}
diff --git a/tests/conftest.py b/tests/conftest.py
index 094399d38b..e8b61db9ce 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -16,7 +16,7 @@ def cart(db): # pylint: disable=W0613
@pytest.fixture
-def normal_user(db):
+def customer_user(db):
return User.objects.create_user('[email protected]', 'password')
@@ -53,8 +53,8 @@ def admin_client(admin_user):
@pytest.fixture()
-def authorized_client(client, normal_user):
- client.login(username=normal_user.email, password='password')
+def authorized_client(client, customer_user):
+ client.login(username=customer_user.email, password='password')
return client
diff --git a/tests/test_checkout_integration.py b/tests/test_checkout_integration.py
index 0770e5d6c8..19cee8a177 100644
--- a/tests/test_checkout_integration.py
+++ b/tests/test_checkout_integration.py
@@ -66,13 +66,13 @@ def test_checkout_flow(request_cart_with_item, client, shipping_method): # pyli
def test_checkout_flow_authenticated_user(authorized_client, billing_address, request_cart_with_item,
- normal_user, shipping_method):
+ customer_user, shipping_method):
"""
Checkout with authenticated user and previously saved address
"""
# Prepare some data
- normal_user.addresses.add(billing_address)
- request_cart_with_item.user = normal_user
+ customer_user.addresses.add(billing_address)
+ request_cart_with_item.user = customer_user
request_cart_with_item.save()
# Enter checkout
@@ -191,14 +191,14 @@ def test_client_login(request_cart_with_item, client, admin_user):
assert response.context['checkout'].cart.token == request_cart_with_item.token
-def test_email_is_saved_in_order(authorized_client, billing_address, normal_user, # pylint: disable=R0914
+def test_email_is_saved_in_order(authorized_client, billing_address, customer_user, # pylint: disable=R0914
request_cart_with_item, shipping_method):
"""
authorized user change own email after checkout - if is not changed in order
"""
# Prepare some data
- normal_user.addresses.add(billing_address)
- request_cart_with_item.user = normal_user
+ customer_user.addresses.add(billing_address)
+ request_cart_with_item.user = customer_user
request_cart_with_item.save()
# Enter checkout
@@ -222,7 +222,7 @@ def test_email_is_saved_in_order(authorized_client, billing_address, normal_user
# After summary step, order is created and it waits for payment
order = payment_method_page.context['order']
- assert order.user_email == normal_user.email
+ assert order.user_email == customer_user.email
# User change email
@@ -234,8 +234,8 @@ def test_email_is_saved_in_order(authorized_client, billing_address, normal_user
url = reverse('registration:change_email', args=[token])
authorized_client.get(url)
- updated_user = User.objects.get(pk=normal_user.pk)
+ updated_user = User.objects.get(pk=customer_user.pk)
order = Order.objects.get(pk=order.pk)
- assert updated_user.email != normal_user.email
- assert updated_user.email == '[email protected]'
- assert order.user_email == normal_user.email
+ assert updated_user.email != customer_user.email
+ assert order.user_email == customer_user.email
+ assert order.get_user_current_email() == updated_user.email