test_aigc_safety.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import annotations
  2. from supply_infra.aigc.client import AigcClient
  3. from supply_infra.config import InfraSettings
  4. def test_aigc_client_requires_token_for_live_calls(monkeypatch) -> None:
  5. settings = InfraSettings(_env_file=None)
  6. monkeypatch.setattr(
  7. "supply_infra.aigc.client.get_infra_settings",
  8. lambda: settings,
  9. )
  10. client = AigcClient(token="")
  11. try:
  12. client.create_video_crawler_plan(["123"])
  13. except RuntimeError as exc:
  14. assert "AIGC_API_TOKEN" in str(exc)
  15. else:
  16. raise AssertionError("missing token must raise")
  17. def test_aigc_client_posts_to_platform(monkeypatch) -> None:
  18. settings = InfraSettings(_env_file=None)
  19. monkeypatch.setattr(
  20. "supply_infra.aigc.client.get_infra_settings",
  21. lambda: settings,
  22. )
  23. class _Response:
  24. def raise_for_status(self) -> None:
  25. return None
  26. def json(self) -> dict:
  27. return {"code": 0, "data": {"id": "plan-1"}}
  28. calls: list[dict] = []
  29. def _post(*, url, json, headers, timeout):
  30. calls.append({"url": url, "json": json})
  31. return _Response()
  32. monkeypatch.setattr("supply_infra.aigc.client.requests.post", _post)
  33. client = AigcClient(token="secret")
  34. result = client.create_video_crawler_plan(["123"])
  35. assert result["success"] is True
  36. assert result["crawler_plan_id"] == "plan-1"
  37. assert len(calls) == 1