Skip to content

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

Rework some of the staff tests failling after conftest Order fixture update

Pacu2c79e49bd209a
diff --git a/tests/dashboard/test_staff.py b/tests/dashboard/test_staff.py
index 4d588bda00..7a4f729943 100644
--- a/tests/dashboard/test_staff.py
+++ b/tests/dashboard/test_staff.py
@@ -19,6 +19,7 @@ def test_staff_form_not_valid(db):
def test_staff_form_create_valid(
admin_client, staff_user, staff_group):
+ assert staff_user.groups.count() == 0
url = reverse('dashboard:staff-details', kwargs={'pk': staff_user.pk})
data = {'email': '[email protected]', 'groups': staff_group.pk}
admin_client.post(url, data)
@@ -49,42 +50,49 @@ def test_admin_cant_change_his_permissions(admin_client, admin_user):
def test_delete_staff(admin_client, staff_user):
- assert User.objects.all().count() == 2
+ user_count = User.objects.all().count()
url = reverse('dashboard:staff-delete', kwargs={'pk': staff_user.pk})
data = {'pk': staff_user.pk}
response = admin_client.post(url, data)
- assert User.objects.all().count() == 1
+ assert User.objects.all().count() == user_count - 1
assert response['Location'] == '/dashboard/staff/'
def test_delete_staff_no_post(admin_client, staff_user):
+ user_count = User.objects.all().count()
url = reverse('dashboard:staff-delete', kwargs={'pk': staff_user.pk})
admin_client.get(url)
- assert User.objects.all().count() == 2
+ assert User.objects.all().count() == user_count
def test_delete_staff_with_orders(admin_client, staff_user, order):
order.user = staff_user
order.save()
- assert User.objects.all().count() == 2
+ user_count = User.objects.all().count()
url = reverse('dashboard:staff-delete', kwargs={'pk': staff_user.pk})
data = {'pk': staff_user.pk}
response = admin_client.post(url, data)
- assert User.objects.all().count() == 2
+
+ # Staff placed some orders in the past, so his acc should be not deleted
+ assert User.objects.all().count() == user_count
staff_user.refresh_from_db()
+ # Instead, his privileges are taken away
assert not staff_user.is_staff
assert response['Location'] == '/dashboard/staff/'
def test_staff_create_email_with_set_link_password(
admin_client, staff_group):
+ user_count = User.objects.count()
+ mail_outbox_count = len(mail.outbox)
url = reverse('dashboard:staff-create')
data = {
'email': '[email protected]', 'groups': staff_group.pk,
'is_staff': True}
response = admin_client.post(url, data)
- assert User.objects.count() == 2
- assert len(mail.outbox) == 1
+
+ assert User.objects.count() == user_count + 1
+ assert len(mail.outbox) == mail_outbox_count + 1
assert response['Location'] == reverse('dashboard:staff-list')