3e9e2f632b
- Instagram: migrate /v1/ to /v2/ ScrapeCreators endpoint (v1 deprecated Feb 2026) - OpenAI: switch fallback chain to [gpt-5-mini, gpt-4.1-mini, gpt-4.1] (8x cheaper, gpt-5-mini is the first mini model supporting web_search with filters.allowed_domains) - xAI: use explicit grok-4-1-fast-non-reasoning (bare name aliases to reasoning variant) - xAI: pass from_date/to_date natively to x_search tool config instead of prompt-only - Polymarket: correct rate limit comment (15K/10s, not 350/10s)
78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
"""Tests for openai_reddit module."""
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
# Add scripts directory to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
|
|
|
|
from lib import http
|
|
from lib.openai_reddit import _is_model_access_error, MODEL_FALLBACK_ORDER
|
|
|
|
|
|
class TestIsModelAccessError(unittest.TestCase):
|
|
"""Tests for _is_model_access_error function."""
|
|
|
|
def test_returns_false_for_non_400_error(self):
|
|
"""Non-400 errors should not trigger fallback."""
|
|
error = http.HTTPError("Server error", status_code=500, body="Internal error")
|
|
self.assertFalse(_is_model_access_error(error))
|
|
|
|
def test_returns_false_for_400_without_body(self):
|
|
"""400 without body should not trigger fallback."""
|
|
error = http.HTTPError("Bad request", status_code=400, body=None)
|
|
self.assertFalse(_is_model_access_error(error))
|
|
|
|
def test_returns_true_for_verification_error(self):
|
|
"""Verification error should trigger fallback."""
|
|
error = http.HTTPError(
|
|
"Bad request",
|
|
status_code=400,
|
|
body='{"error": {"message": "Your organization must be verified to use the model \'gpt-5.2\'"}}'
|
|
)
|
|
self.assertTrue(_is_model_access_error(error))
|
|
|
|
def test_returns_true_for_access_error(self):
|
|
"""Access denied error should trigger fallback."""
|
|
error = http.HTTPError(
|
|
"Bad request",
|
|
status_code=400,
|
|
body='{"error": {"message": "Your account does not have access to this model"}}'
|
|
)
|
|
self.assertTrue(_is_model_access_error(error))
|
|
|
|
def test_returns_true_for_model_not_found(self):
|
|
"""Model not found error should trigger fallback."""
|
|
error = http.HTTPError(
|
|
"Bad request",
|
|
status_code=400,
|
|
body='{"error": {"message": "The model gpt-5.2 was not found"}}'
|
|
)
|
|
self.assertTrue(_is_model_access_error(error))
|
|
|
|
def test_returns_false_for_unrelated_400(self):
|
|
"""Unrelated 400 errors should not trigger fallback."""
|
|
error = http.HTTPError(
|
|
"Bad request",
|
|
status_code=400,
|
|
body='{"error": {"message": "Invalid JSON in request body"}}'
|
|
)
|
|
self.assertFalse(_is_model_access_error(error))
|
|
|
|
|
|
class TestModelFallbackOrder(unittest.TestCase):
|
|
"""Tests for MODEL_FALLBACK_ORDER constant."""
|
|
|
|
def test_contains_gpt41(self):
|
|
"""Fallback list should include gpt-4.1 as last resort."""
|
|
self.assertIn("gpt-4.1", MODEL_FALLBACK_ORDER)
|
|
|
|
def test_gpt5_mini_is_first(self):
|
|
"""gpt-5-mini should be the first fallback option (cheapest with web_search support)."""
|
|
self.assertEqual(MODEL_FALLBACK_ORDER[0], "gpt-5-mini")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|