igdb search + capped http reads: native fulltext, full-page fetch
search_games used `where name ~ "<q>"*`: prefix-only, diacritic- and word-order-sensitive -- "MARVEL Tōkon" found nothing though IGDB has it. Switch to IGDB's native `search` clause (relevance-ranked, diacritic-insensitive). fetch_url and image downloads read bodies with content.read(n), which returns only the first buffered chunk (~7 KB): pages collapsed to their <title>. httpread.read_capped collects chunks up to the byte cap; image downloads read limit+1 so over-limit files are still rejected instead of cached truncated (IMG-10). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -174,6 +174,25 @@ class TestIGDBQuery(unittest.TestCase):
|
||||
self.assertEqual(result, [{"id": 1, "name": "Super Mario Bros"}])
|
||||
|
||||
|
||||
class TestIGDBNativeSearch(unittest.TestCase):
|
||||
def test_build_query_with_search_term(self):
|
||||
"""search_games uses IGDB full-text search, not a name prefix filter."""
|
||||
query = IGDBQuery.build_query(["name"], {"game_type": "= 0"}, limit=5, search_term="Marvel Tōkon")
|
||||
self.assertEqual(query, 'search "Marvel Tōkon"; fields name; limit 5; where game_type = 0;')
|
||||
|
||||
def test_search_term_escapes_quotes_and_backslashes(self):
|
||||
query = IGDBQuery.build_query(["name"], search_term='say "hi" \\ bye')
|
||||
self.assertIn('search "say \\"hi\\" \\\\ bye";', query)
|
||||
|
||||
@patch.object(IGDBQuery, "generalized_igdb_query")
|
||||
def test_search_games_passes_search_term(self, mock_query):
|
||||
mock_query.return_value = []
|
||||
IGDBQuery("cid", "token").search_games("Elden Ring", limit=3)
|
||||
_, kwargs = mock_query.call_args
|
||||
self.assertEqual(kwargs["search_term"], "Elden Ring")
|
||||
self.assertEqual(mock_query.call_args.args[0], {})
|
||||
|
||||
|
||||
class TestIGDBTokenRefresh(unittest.TestCase):
|
||||
@staticmethod
|
||||
def _oauth_response(token="fresh_token", expires_in=5_000_000):
|
||||
|
||||
Reference in New Issue
Block a user