Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Tests
Pacu2530986bf8551
diff --git a/saleor/account/urls.py b/saleor/account/urls.pyindex 78f5c62c2f..663aaf490c 100644--- a/saleor/account/urls.py+++ b/saleor/account/urls.py@@ -25,6 +25,6 @@ urlpatterns = [url(r'^address/(?P<pk>\d+)/delete/$',views.address_delete, name='address-delete'),url(r'^(?P<pk>\d+)/delete/$', views.account_delete,- name='account-delete'),- url(r'^(?P<token>[0-9A-Za-z_\-]+)/delete/',- views.account_delete_confirm, name='account-delete-confirm')]+ name='delete'),+ url(r'^(?P<token>[0-9A-Za-z_\-]+)/delete-confirm/',+ views.account_delete_confirm, name='delete-confirm')]diff --git a/saleor/account/views.py b/saleor/account/views.pyindex 8f3ce8f614..a029683f9a 100755--- a/saleor/account/views.py+++ b/saleor/account/views.py@@ -134,7 +134,7 @@ def account_delete(request, pk):if request.user.pk != user.pk:raise Http404('No such page!')- send_account_delete_confirmation_email.delay()+ send_account_delete_confirmation_email.delay(pk)messages.success(request, pgettext('Storefront message, when user requested his account removed',diff --git a/tests/test_account.py b/tests/test_account.pyindex c5e7fe064a..19a75c1836 100644--- a/tests/test_account.py+++ b/tests/test_account.py@@ -1,20 +1,21 @@import jsonimport os+import uuidfrom unittest.mock import patchfrom urllib.parse import urlencode-import i18naddressimport pytest++import i18naddressfrom captcha import constants as recaptcha_constants-from django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom django.forms import Formfrom django.http import QueryDictfrom django.template import Context, Templatefrom django.urls import reversefrom django_countries.fields import Country-from saleor.account import forms, i18n+from saleor.account.forms import FormWithReCaptchafrom saleor.account.templatetags.i18n_address_tags import format_addressfrom saleor.account.validators import validate_possible_number@@ -229,8 +230,6 @@ def test_disabled_recaptcha():"""This test creates a new form that should not contain any recaptcha field."""- from saleor.account.forms import FormWithReCaptcha-class TestForm(Form, FormWithReCaptcha):pass@@ -239,16 +238,13 @@ def test_disabled_recaptcha():@patch.dict(os.environ, {'RECAPTCHA_TESTING': 'True'})- settings, 'RECAPTCHA_PUBLIC_KEY', recaptcha_constants.TEST_PUBLIC_KEY)- settings, 'RECAPTCHA_PRIVATE_KEY', recaptcha_constants.TEST_PRIVATE_KEY)-def test_requires_recaptcha():+def test_requires_recaptcha(settings):"""This test creates a new formthat should contain a (required) recaptcha field."""- from saleor.account.forms import FormWithReCaptcha+ settings.RECAPTCHA_PUBLIC_KEY = recaptcha_constants.TEST_PUBLIC_KEY+ settings.RECAPTCHA_PRIVATE_KEY = recaptcha_constants.TEST_PRIVATE_KEYclass TestForm(Form, FormWithReCaptcha):pass@@ -258,3 +254,42 @@ def test_requires_recaptcha():form = TestForm({'g-recaptcha-response': 'PASSED'})assert form.is_valid()+++def test_view_account_delete_login_required(customer_user, client):+ url = reverse('account:delete', args=[444])+ response = client.post(url)+ assert response.status_code == 302+++def test_view_account_post_required(customer_user, authorized_client):+ url = reverse('account:delete', args=[444])+ response = authorized_client.get(url)+ assert response.status_code == 405+++@patch('saleor.account.views.send_account_delete_confirmation_email.delay')+def test_view_account_delete(+ send_confirmation_mock, customer_user, authorized_client, staff_user):+ # User requests account delete for another user+ url = reverse('account:delete', args=[staff_user.pk])+ response = authorized_client.post(url)+ assert response.status_code == 404++ url = reverse('account:delete', args=[customer_user.pk])+ response = authorized_client.post(url)+ assert response.status_code == 302+ send_confirmation_mock.assert_called_once_with(str(customer_user.pk))+++def test_view_account_delete_confirm(customer_user, authorized_client):+ # Non existing token+ url = reverse('account:delete-confirm', args=[str(uuid.uuid4())])+ response = authorized_client.get(url)+ assert response.status_code == 404++ url = reverse('account:delete-confirm', args=[customer_user.token])+ response = authorized_client.get(url)+ assert response.status_code == 200+ customer_user.refresh_from_db()+ assert customer_user is None