style: auto-fix black formatting
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 53s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 54s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 44s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m3s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m34s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m19s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m40s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 59s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 59s
AI Code Review / AI Code Review (pull_request) Successful in 6m17s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 13m9s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 2m51s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 3m47s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 34m6s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1339h38m36s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 1340h1m55s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1340h1m59s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1340h2m1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 1340h32m24s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1340h34m40s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 1340h34m46s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 1340h34m42s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 1340h59m14s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 1340h59m18s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 1341h31m32s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 1341h7m0s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1340h34m13s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 53s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 54s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 44s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m3s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m34s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m19s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m40s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 59s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 59s
AI Code Review / AI Code Review (pull_request) Successful in 6m17s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 13m9s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 2m51s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 3m47s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 34m6s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1339h38m36s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 1340h1m55s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1340h1m59s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1340h2m1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 1340h32m24s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1340h34m40s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 1340h34m46s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 1340h34m42s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 1340h59m14s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 1340h59m18s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 1341h31m32s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 1341h7m0s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1340h34m13s
This commit is contained in:
@@ -120,9 +120,7 @@ class TestGenerateNormal:
|
||||
mock_repo.find_latest.return_value = None
|
||||
mock_repo.count_today.return_value = 0
|
||||
|
||||
code, err = service.generate(
|
||||
"test@example.com", CODE_TYPE_EMAIL_BIND, custom_code="888888"
|
||||
)
|
||||
code, err = service.generate("test@example.com", CODE_TYPE_EMAIL_BIND, custom_code="888888")
|
||||
|
||||
assert err is None
|
||||
assert code.code == "888888"
|
||||
@@ -132,9 +130,7 @@ class TestGenerateNormal:
|
||||
mock_repo.find_latest.return_value = None
|
||||
mock_repo.count_today.return_value = 0
|
||||
|
||||
code, err = service.generate(
|
||||
"test@example.com", CODE_TYPE_EMAIL_BIND, ttl_seconds=60
|
||||
)
|
||||
code, err = service.generate("test@example.com", CODE_TYPE_EMAIL_BIND, ttl_seconds=60)
|
||||
|
||||
assert err is None
|
||||
# 过期时间 - 创建时间 ≈ 60 秒
|
||||
@@ -174,9 +170,7 @@ class TestGenerateRateLimit:
|
||||
def test_resend_cooldown_blocked(self, service, mock_repo):
|
||||
"""冷却期内发送被拒绝"""
|
||||
# 10 秒前刚发过一条
|
||||
recent = make_code(
|
||||
created_at=datetime.now(timezone.utc) - timedelta(seconds=10)
|
||||
)
|
||||
recent = make_code(created_at=datetime.now(timezone.utc) - timedelta(seconds=10))
|
||||
mock_repo.find_latest.return_value = recent
|
||||
mock_repo.count_today.return_value = 1
|
||||
|
||||
@@ -188,6 +182,7 @@ class TestGenerateRateLimit:
|
||||
# 等待时间应接近 50 秒(60-10)
|
||||
# 提取数字验证范围
|
||||
import re
|
||||
|
||||
match = re.search(r"(\d+)\s*秒", err)
|
||||
assert match
|
||||
wait = int(match.group(1))
|
||||
@@ -196,9 +191,7 @@ class TestGenerateRateLimit:
|
||||
def test_resend_after_cooldown_ok(self, service, mock_repo):
|
||||
"""超过冷却期可以重发"""
|
||||
# 2 分钟前发的,已过冷却
|
||||
old = make_code(
|
||||
created_at=datetime.now(timezone.utc) - timedelta(seconds=120)
|
||||
)
|
||||
old = make_code(created_at=datetime.now(timezone.utc) - timedelta(seconds=120))
|
||||
mock_repo.find_latest.return_value = old
|
||||
mock_repo.count_today.return_value = 1
|
||||
|
||||
@@ -210,9 +203,7 @@ class TestGenerateRateLimit:
|
||||
def test_daily_limit_reached(self, service, mock_repo):
|
||||
"""达到每日上限"""
|
||||
# 没有最近的(过了冷却),但今日已达上限
|
||||
old = make_code(
|
||||
created_at=datetime.now(timezone.utc) - timedelta(hours=2)
|
||||
)
|
||||
old = make_code(created_at=datetime.now(timezone.utc) - timedelta(hours=2))
|
||||
mock_repo.find_latest.return_value = old
|
||||
mock_repo.count_today.return_value = DAILY_LIMIT
|
||||
|
||||
@@ -253,13 +244,9 @@ class TestGenerateCustomRateLimitParams:
|
||||
|
||||
def test_custom_cooldown(self, mock_repo):
|
||||
"""自定义冷却时间"""
|
||||
svc = VerificationCodeService(
|
||||
repo=mock_repo, resend_cooldown=300, daily_limit=5
|
||||
)
|
||||
svc = VerificationCodeService(repo=mock_repo, resend_cooldown=300, daily_limit=5)
|
||||
# 60 秒前发的,默认冷却 60 秒就够了,但这里设了 300 秒
|
||||
recent = make_code(
|
||||
created_at=datetime.now(timezone.utc) - timedelta(seconds=60)
|
||||
)
|
||||
recent = make_code(created_at=datetime.now(timezone.utc) - timedelta(seconds=60))
|
||||
mock_repo.find_latest.return_value = recent
|
||||
mock_repo.count_today.return_value = 1
|
||||
|
||||
@@ -270,9 +257,7 @@ class TestGenerateCustomRateLimitParams:
|
||||
|
||||
def test_custom_daily_limit(self, mock_repo):
|
||||
"""自定义每日上限"""
|
||||
svc = VerificationCodeService(
|
||||
repo=mock_repo, resend_cooldown=60, daily_limit=3
|
||||
)
|
||||
svc = VerificationCodeService(repo=mock_repo, resend_cooldown=60, daily_limit=3)
|
||||
mock_repo.find_latest.return_value = None
|
||||
mock_repo.count_today.return_value = 3
|
||||
|
||||
@@ -308,9 +293,7 @@ class TestVerifyParamValidation:
|
||||
mock_repo.find_latest.return_value = code
|
||||
mock_repo.count_today.return_value = 0
|
||||
|
||||
ok, err = service.verify(
|
||||
" test@example.com ", CODE_TYPE_EMAIL_BIND, " 123456 "
|
||||
)
|
||||
ok, err = service.verify(" test@example.com ", CODE_TYPE_EMAIL_BIND, " 123456 ")
|
||||
|
||||
assert ok
|
||||
assert err is None
|
||||
@@ -329,9 +312,7 @@ class TestVerifyNormal:
|
||||
code = make_code(code="123456")
|
||||
mock_repo.find_latest.return_value = code
|
||||
|
||||
ok, err = service.verify(
|
||||
"test@example.com", CODE_TYPE_EMAIL_BIND, "123456", consume=True
|
||||
)
|
||||
ok, err = service.verify("test@example.com", CODE_TYPE_EMAIL_BIND, "123456", consume=True)
|
||||
|
||||
assert ok
|
||||
assert err is None
|
||||
@@ -344,9 +325,7 @@ class TestVerifyNormal:
|
||||
code = make_code(code="123456")
|
||||
mock_repo.find_latest.return_value = code
|
||||
|
||||
ok, err = service.verify(
|
||||
"test@example.com", CODE_TYPE_EMAIL_BIND, "123456", consume=False
|
||||
)
|
||||
ok, err = service.verify("test@example.com", CODE_TYPE_EMAIL_BIND, "123456", consume=False)
|
||||
|
||||
assert ok
|
||||
assert err is None
|
||||
@@ -438,9 +417,7 @@ class TestVerifyCodeTypeIsolation:
|
||||
|
||||
mock_repo.find_latest.side_effect = side_effect
|
||||
|
||||
ok, err = service.verify(
|
||||
"test@example.com", CODE_TYPE_EMAIL_BIND, "123456"
|
||||
)
|
||||
ok, err = service.verify("test@example.com", CODE_TYPE_EMAIL_BIND, "123456")
|
||||
assert not ok
|
||||
assert "不存在或已过期" in err
|
||||
|
||||
@@ -468,4 +445,5 @@ class TestConstants:
|
||||
def test_valid_code_types_count(self):
|
||||
"""5 种验证码类型"""
|
||||
from packages.application.auth.verification_code_service import VALID_CODE_TYPES
|
||||
|
||||
assert len(VALID_CODE_TYPES) == 5
|
||||
|
||||
Reference in New Issue
Block a user