Skip to content

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

Add test for first and last name in dashboard and user profil

fowczarekcca05285889b
diff --git a/tests/dashboard/test_customer.py b/tests/dashboard/test_customer.py
index 9ff1a376f6..435f052284 100644
--- a/tests/dashboard/test_customer.py
+++ b/tests/dashboard/test_customer.py
@@ -3,7 +3,8 @@ import json
from django.urls import reverse
from saleor.account.models import CustomerNote, User
-from saleor.dashboard.customer.forms import CustomerDeleteForm, CustomerNoteForm
+from saleor.dashboard.customer.forms import (
+ CustomerDeleteForm, CustomerForm, CustomerNoteForm)
def test_ajax_users_list(admin_client, admin_user, customer_user):
@@ -34,6 +35,33 @@ def test_customer_create(admin_client):
assert response.status_code == 200
+def test_customer_create_post(admin_client):
+ url = reverse('dashboard:customer-create')
+ response = admin_client.post(url, data={'email': '[email protected]'})
+ assert response.status_code == 302
+ assert User.objects.filter(email='[email protected]').exists()
+
+
+def test_add_customer_form():
+ user_count = User.objects.count()
+ customer_form = CustomerForm({'email': '[email protected]'})
+ customer_form.is_valid()
+ customer_form.save()
+ assert User.objects.count() == user_count + 1
+
+
+def test_add_names_to_customer(customer_user):
+ customer = customer_user
+ customer_form = CustomerForm(
+ {'first_name': 'Jan', 'last_name': 'Nowak', 'email': customer.email},
+ instance=customer)
+ customer_form.is_valid()
+ customer_form.save()
+ updated_user = User.objects.get(pk=customer_user.pk)
+ assert updated_user.first_name == 'Jan'
+ assert updated_user.last_name == 'Nowak'
+
+
def test_add_note_to_customer(admin_user, customer_user):
customer = customer_user
note = CustomerNote(customer=customer, user=admin_user)
diff --git a/tests/dashboard/test_staff.py b/tests/dashboard/test_staff.py
index 1468b8d4cf..286706e63e 100644
--- a/tests/dashboard/test_staff.py
+++ b/tests/dashboard/test_staff.py
@@ -145,10 +145,14 @@ def test_send_set_password_email(staff_user, site_settings):
def test_create_staff_and_set_password(admin_client):
url = reverse('dashboard:staff-create')
- data = {'email': '[email protected]', 'is_staff': True}
+ data = {
+ 'first_name': 'Jan', 'last_name': 'Nowak',
+ 'email': '[email protected]', 'is_staff': True}
response = admin_client.post(url, data)
assert response.status_code == 302
new_user = User.objects.get(email='[email protected]')
+ assert new_user.first_name == 'Jan'
+ assert new_user.last_name == 'Nowak'
assert not new_user.password
uid = urlsafe_base64_encode(force_bytes(new_user.pk)).decode()
token = default_token_generator.make_token(new_user)
diff --git a/tests/test_account.py b/tests/test_account.py
index b18ad001ab..5fea597d5c 100644
--- a/tests/test_account.py
+++ b/tests/test_account.py
@@ -14,7 +14,7 @@ from django.template import Context, Template
from django.urls import reverse
from django_countries.fields import Country
from saleor.account import forms, i18n
-from saleor.account.forms import FormWithReCaptcha
+from saleor.account.forms import FormWithReCaptcha, NameForm
from saleor.account.models import User
from saleor.account.templatetags.i18n_address_tags import format_address
from saleor.account.validators import validate_possible_number
@@ -285,3 +285,24 @@ def test_view_account_delete_confirm(customer_user, authorized_client):
assert response.status_code == 302
customer_user = User.objects.filter(pk=customer_user.pk).first()
assert customer_user is None
+
+
+def test_add_names_to_user(customer_user):
+ name_form = NameForm(
+ {'first_name': 'Jan', 'last_name': 'Nowak'},
+ instance=customer_user)
+ name_form.is_valid()
+ name_form.save()
+ updated_user = User.objects.get(pk=customer_user.pk)
+ assert updated_user.first_name == 'Jan'
+ assert updated_user.last_name == 'Nowak'
+
+
+def test_add_names_to_user_post(customer_user, authorized_client):
+ url = reverse('account:details')
+ response = authorized_client.post(
+ url, data={'first_name': 'Jan', 'last_name': 'Nowak'})
+ assert response.status_code == 200
+ updated_user = User.objects.get(pk=customer_user.pk)
+ assert updated_user.first_name == 'Jan'
+ assert updated_user.last_name == 'Nowak'