block user in django admin
This commit is contained in:
1 parent
089db0afa4
commit
fe7a10cb61
19 files changed
+574
-11
No files matched your search
@@ -0,0 +1,25 @@
|
||||
from django.urls import reverse
|
||||
from playwright.sync_api import expect
|
||||
|
||||
from tests.e2e.pages.auth import AuthenticationPage
|
||||
|
||||
|
||||
class CustomerLoginAccessPage(AuthenticationPage):
|
||||
def request_otp(self, mobile):
|
||||
self.goto(reverse("accounts:login"))
|
||||
self.page.get_by_label("شماره موبایل").fill(mobile)
|
||||
self.page.get_by_role("button", name="دریافت کد یکبارمصرف").click()
|
||||
|
||||
def assert_block_reason(self, reason):
|
||||
alert = self.page.get_by_role("alert")
|
||||
expect(alert).to_contain_text("ورود به حساب شما مسدود است")
|
||||
expect(alert).to_contain_text(reason)
|
||||
expect(alert).to_be_visible()
|
||||
assert alert.locator(".customer-login-block-reason").evaluate(
|
||||
"node => getComputedStyle(node).color"
|
||||
) == "rgb(153, 27, 27)"
|
||||
assert self.page.evaluate("document.documentElement.scrollWidth <= innerWidth + 1")
|
||||
|
||||
def assert_logged_out(self, reason):
|
||||
expect(self.page).to_have_url(self.url(reverse("accounts:login")), timeout=20000)
|
||||
self.assert_block_reason(reason)
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user