block user in django admin

This commit is contained in:
javad committed 2026-10-14 12:27:55 +03:30
1 parent 089db0afa4
commit fe7a10cb61
19 files changed
+574 -11

No files matched your search

@@ -0,0 +1,44 @@
import pytest
from concurrent.futures import ThreadPoolExecutor
from django.db import connections
from apps.accounts.models import User
from apps.customers.models import CustomerProfile
from tests.e2e.pages.customer_login_access import CustomerLoginAccessPage
pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)]
REASON = "به علت بدهی معوق، ورود شما تا بررسی واحد مالی مسدود شده است."
PASSWORD = "Customer-access-e2e-2026!"
def block_customer(profile_id):
try:
profile = CustomerProfile.objects.get(pk=profile_id)
profile.login_blocked = True
profile.login_block_reason = REASON
profile.save(update_fields=["login_blocked", "login_block_reason"])
finally:
connections.close_all()
@pytest.mark.parametrize("width", [320, 1280])
def test_block_reason_is_clear_and_red_on_mobile_and_desktop(live_server, browser_page, width):
user = User.objects.create_user(username="blocked-ui", mobile="09121234566", password=PASSWORD)
CustomerProfile.objects.create(user=user, login_blocked=True, login_block_reason=REASON)
with browser_page() as page:
page.set_viewport_size({"width": width, "height": 850})
access = CustomerLoginAccessPage(page, live_server.url)
access.request_otp(user.local_mobile)
access.assert_block_reason(REASON)
def test_open_customer_browser_logs_out_without_interaction(live_server, browser_page):
user = User.objects.create_user(username="idle-ui", mobile="09121234566", password=PASSWORD)
profile = CustomerProfile.objects.create(user=user)
with browser_page() as page:
access = CustomerLoginAccessPage(page, live_server.url)
access.login_customer(user, PASSWORD)
with ThreadPoolExecutor(max_workers=1) as executor:
executor.submit(block_customer, profile.pk).result()
access.assert_logged_out(REASON)