Extract relevance_filter, add Bluesky/TruthSocial type hint + test coverage
- Extract _relevance_filter from last30days.py closure to score.relevance_filter() for testability - Add BlueskyItem/TruthSocialItem to sort_items() type hint (was missing despite being in _ITEM_SOURCE_MAP) - Add tests: Bluesky/TruthSocial engagement scoring, sort_items mixed sources, relevance_filter behavior (threshold, minimum-result guarantee, missing attr), select_openai_model HTTP 401/403 error paths
This commit is contained in:
@@ -140,6 +140,27 @@ class TestSelectOpenAIModel(unittest.TestCase):
|
||||
self.assertEqual(result, "gpt-4.1-mini")
|
||||
|
||||
|
||||
class TestSelectOpenAIModelErrorPaths(unittest.TestCase):
|
||||
def setUp(self):
|
||||
from lib import cache
|
||||
cache.MODEL_CACHE_FILE.unlink(missing_ok=True)
|
||||
|
||||
def test_http_error_returns_fallback(self):
|
||||
"""HTTPError during model fetch should return fallback, not crash."""
|
||||
from unittest.mock import patch
|
||||
from lib import http
|
||||
with patch('lib.http.get', side_effect=http.HTTPError("Unauthorized", status_code=401)):
|
||||
result = models.select_openai_model("bad-key", policy="auto")
|
||||
self.assertEqual(result, models.OPENAI_FALLBACK_MODELS[0])
|
||||
|
||||
def test_http_403_returns_fallback(self):
|
||||
from unittest.mock import patch
|
||||
from lib import http
|
||||
with patch('lib.http.get', side_effect=http.HTTPError("Forbidden", status_code=403)):
|
||||
result = models.select_openai_model("bad-key", policy="auto")
|
||||
self.assertEqual(result, models.OPENAI_FALLBACK_MODELS[0])
|
||||
|
||||
|
||||
class TestSelectXAIModel(unittest.TestCase):
|
||||
def test_latest_policy(self):
|
||||
result = models.select_xai_model(
|
||||
|
||||
Reference in New Issue
Block a user