test_ad_creation_status.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import sys
  2. import unittest
  3. from pathlib import Path
  4. from unittest.mock import patch
  5. ROOT = Path(__file__).resolve().parent
  6. if str(ROOT) not in sys.path:
  7. sys.path.insert(0, str(ROOT))
  8. PROJECT_ROOT = ROOT.parents[1]
  9. if str(PROJECT_ROOT) not in sys.path:
  10. sys.path.insert(0, str(PROJECT_ROOT))
  11. from tools.ad_creation import AdCandidate, build_ad_request_body
  12. def _candidate() -> AdCandidate:
  13. return AdCandidate(
  14. account_id=123,
  15. adgroup_name="test-ad",
  16. site_set=["SITE_SET_WECHAT"],
  17. custom_audience=None,
  18. bid_amount_fen=35,
  19. audience_tier_label="泛人群",
  20. age=[{"min": 45, "max": 66}],
  21. location_types=["LIVE_IN"],
  22. region_ids=[1],
  23. daily_budget_fen=10000,
  24. time_series="1" * 48,
  25. delivery_version="miniapp_user_growth_v1",
  26. fingerprint="fp",
  27. wechat_position=None,
  28. )
  29. class AdCreationStatusTest(unittest.TestCase):
  30. def test_ad_request_defaults_to_normal_status(self):
  31. with patch("tools.ad_creation.get_account_feedback_id", return_value=6700001):
  32. body = build_ad_request_body(_candidate(), begin_date="2026-07-01")
  33. self.assertEqual(body["configured_status"], "AD_STATUS_NORMAL")
  34. if __name__ == "__main__":
  35. unittest.main()