ccd8387287
AI Code Review / AI Code Review (pull_request) Failing after 0s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 18s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 56s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 48s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 28s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 35s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 29s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 16s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m51s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m24s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m13s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m7s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m2s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 48m5s
新增86个测试: - test_domain_exceptions +20(新建:DomainError/NotFoundError/ValidationError/QuotaExceededError) - test_template_domain +28(tags/config独立性、零值大值负值、长名称unicode、多segments等) - test_template_version_domain +16(id hex/唯一性、零值负值大值version、复杂config等) - test_edit_template_domain +22(id hex/唯一性、长描述、sort_weight边界、状态切换等)
115 lines
3.3 KiB
Python
Executable File
115 lines
3.3 KiB
Python
Executable File
"""
|
|
领域层异常类单元测试
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from packages.domain.exceptions import (
|
|
DomainError,
|
|
NotFoundError,
|
|
QuotaExceededError,
|
|
ValidationError,
|
|
)
|
|
|
|
|
|
class TestDomainError:
|
|
"""DomainError 基类测试"""
|
|
|
|
def test_is_exception(self):
|
|
assert issubclass(DomainError, Exception)
|
|
|
|
def test_raise_and_catch(self):
|
|
with pytest.raises(DomainError):
|
|
raise DomainError("test error")
|
|
|
|
def test_error_message(self):
|
|
err = DomainError("something went wrong")
|
|
assert str(err) == "something went wrong"
|
|
|
|
def test_empty_message(self):
|
|
err = DomainError("")
|
|
assert str(err) == ""
|
|
|
|
|
|
class TestNotFoundError:
|
|
"""NotFoundError 测试"""
|
|
|
|
def test_is_domain_error(self):
|
|
assert issubclass(NotFoundError, DomainError)
|
|
|
|
def test_raise_and_catch_as_domain(self):
|
|
with pytest.raises(DomainError):
|
|
raise NotFoundError("resource not found")
|
|
|
|
def test_raise_and_catch_specific(self):
|
|
with pytest.raises(NotFoundError):
|
|
raise NotFoundError("not found")
|
|
|
|
def test_error_message(self):
|
|
err = NotFoundError("user 123 not found")
|
|
assert "user 123 not found" in str(err)
|
|
|
|
|
|
class TestValidationError:
|
|
"""ValidationError 测试"""
|
|
|
|
def test_is_domain_error(self):
|
|
assert issubclass(ValidationError, DomainError)
|
|
|
|
def test_raise_and_catch_as_domain(self):
|
|
with pytest.raises(DomainError):
|
|
raise ValidationError("invalid input")
|
|
|
|
def test_raise_and_catch_specific(self):
|
|
with pytest.raises(ValidationError):
|
|
raise ValidationError("validation failed")
|
|
|
|
def test_error_message(self):
|
|
err = ValidationError("name cannot be empty")
|
|
assert "name cannot be empty" in str(err)
|
|
|
|
|
|
class TestQuotaExceededError:
|
|
"""QuotaExceededError 测试"""
|
|
|
|
def test_is_domain_error(self):
|
|
assert issubclass(QuotaExceededError, DomainError)
|
|
|
|
def test_constructor_sets_attributes(self):
|
|
err = QuotaExceededError(dimension="storage", limit=1024.0, used=2048.0)
|
|
assert err.dimension == "storage"
|
|
assert err.limit == 1024.0
|
|
assert err.used == 2048.0
|
|
|
|
def test_error_message_format(self):
|
|
err = QuotaExceededError(dimension="storage", limit=1024.0, used=2048.0)
|
|
msg = str(err)
|
|
assert "storage" in msg
|
|
assert "2048.0" in msg
|
|
assert "1024.0" in msg
|
|
assert "Quota exceeded" in msg
|
|
|
|
def test_raise_and_catch_as_domain(self):
|
|
with pytest.raises(DomainError):
|
|
raise QuotaExceededError("projects", 10, 15)
|
|
|
|
def test_raise_and_catch_specific(self):
|
|
with pytest.raises(QuotaExceededError):
|
|
raise QuotaExceededError("render", 5, 10)
|
|
|
|
def test_zero_limit(self):
|
|
err = QuotaExceededError(dimension="test", limit=0.0, used=1.0)
|
|
assert err.limit == 0.0
|
|
assert err.used == 1.0
|
|
|
|
def test_negative_values(self):
|
|
"""负数也能存(领域层不做额外校验)"""
|
|
err = QuotaExceededError(dimension="test", limit=-5.0, used=-3.0)
|
|
assert err.limit == -5.0
|
|
assert err.used == -3.0
|
|
|
|
def test_large_values(self):
|
|
err = QuotaExceededError(dimension="storage", limit=1e9, used=1.5e9)
|
|
assert err.limit == 1e9
|
|
assert err.used == 1.5e9
|