Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for changing active status of the superuser
Adam Janik45b76c6a474a
diff --git a/saleor/graphql/account/bulk_mutations.py b/saleor/graphql/account/bulk_mutations.pyindex a5534f131c..fdb0cc8c34 100644--- a/saleor/graphql/account/bulk_mutations.py+++ b/saleor/graphql/account/bulk_mutations.py@@ -59,10 +59,12 @@ class UserBulkSetActive(BaseBulkMutation):def clean_instance(cls, info, instance):if info.context.user == instance:raise ValidationError({- 'is_active': 'Cannot activate or deactivate your own account.'})+ 'is_active':+ 'Cannot activate or deactivate your own account.'})elif instance.is_superuser:raise ValidationError({- 'is_active': 'Cannot activate or deactivate superuser\'s account.'})+ 'is_active':+ 'Cannot activate or deactivate superuser\'s account.'})@classmethoddef bulk_action(cls, queryset, is_active):diff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex 47623b19f3..e61cc8e0bc 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -1674,3 +1674,23 @@ def test_staff_bulk_set_not_active(assert data['count'] == len(users)users = User.objects.filter(pk__in=[user.pk for user in users])assert not any(user.is_active for user in users)+++def test_change_active_status_for_superuser(+ staff_api_client, superuser, permission_manage_users):+ users = [superuser]+ superuser_id = graphene.Node.to_global_id('User', superuser.id)+ active_status = False+ variables = {+ 'ids': [+ graphene.Node.to_global_id('User', user.id)+ for user in users],+ 'is_active': active_status}+ response = staff_api_client.post_graphql(+ USER_CHANGE_ACTIVE_STATUS_MUTATION, variables,+ permissions=[permission_manage_users])+ content = get_graphql_content(response)+ data = content['data']['userBulkSetActive']+ assert data['errors'][0]['field'] == superuser_id+ assert data['errors'][0]['message'] == 'Cannot activate or deactivate ' \+ 'superuser\'s account.'