35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import pytest
|
|||
|
|
|
||
|
|
from app.core.contracts import RequestContext
|
||
|
|
from app.service.agent.bootstrap import get_agent_factory
|
||
|
|
from app.service.promotion_material_service import PromotionMaterialService
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.asyncio
|
||
|
|
async def test_promotion_service_uses_dedicated_write_permission(monkeypatch) -> None:
|
||
|
|
observed: list[str] = []
|
||
|
|
|
||
|
|
async def require(context: RequestContext, permission: str, *, admin: bool = False) -> None:
|
||
|
|
del context, admin
|
||
|
|
observed.append(permission)
|
||
|
|
|
||
|
|
monkeypatch.setattr(
|
||
|
|
"app.service.promotion_material_service.AuthorizationService.require",
|
||
|
|
require,
|
||
|
|
)
|
||
|
|
|
||
|
|
await PromotionMaterialService._require(
|
||
|
|
RequestContext(user_id="1", trace_id="promotion-test"),
|
||
|
|
"promotion:write",
|
||
|
|
)
|
||
|
|
|
||
|
|
assert observed == ["promotion:write"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_promotion_material_agent_is_registered_in_shared_factory() -> None:
|
||
|
|
definition = get_agent_factory().definition("promotion_material")
|
||
|
|
|
||
|
|
assert definition.agent_type == "promotion_material"
|
||
|
|
assert "operator" in definition.allowed_roles
|
||
|
|
assert "promotion_draft" in definition.supported_intents
|