Fixes and improvements.

This commit is contained in:
OK
2025-08-09 00:16:37 +02:00
parent 38f0479d1e
commit d742ab86fa
22 changed files with 529 additions and 457 deletions
+22 -38
View File
@@ -88,7 +88,6 @@ class TestIGDBQuery(unittest.TestCase):
params = {"name": "Mario"}
result = self.igdb.generalized_igdb_query(params, "games", ["name"], limit=5)
expected_filters = {"name": '~ "Mario"*'}
expected_query = 'fields name; limit 5; where name ~ "Mario"*;'
mock_send.assert_called_once_with("games", expected_query)
@@ -101,21 +100,14 @@ class TestIGDBQuery(unittest.TestCase):
params = {"name": "Mario"}
additional_filters = {"platform": "= 1"}
result = self.igdb.generalized_igdb_query(params, "games", ["name"], additional_filters, limit=5)
self.igdb.generalized_igdb_query(params, "games", ["name"], additional_filters, limit=5)
expected_query = 'fields name; limit 5; where name ~ "Mario"* & platform = 1;'
mock_send.assert_called_once_with("games", expected_query)
def test_create_query_function(self):
"""Test creating a query function."""
func_def = self.igdb.create_query_function(
"test_func",
"Test function",
{"name": {"type": "string"}},
"games",
["name"],
limit=5
)
func_def = self.igdb.create_query_function("test_func", "Test function", {"name": {"type": "string"}}, "games", ["name"], limit=5)
self.assertEqual(func_def["name"], "test_func")
self.assertEqual(func_def["description"], "Test function")
@@ -125,10 +117,7 @@ class TestIGDBQuery(unittest.TestCase):
@patch.object(IGDBQuery, "generalized_igdb_query")
def test_platform_families(self, mock_query):
"""Test platform families caching."""
mock_query.return_value = [
{"id": 1, "name": "PlayStation"},
{"id": 2, "name": "Nintendo"}
]
mock_query.return_value = [{"id": 1, "name": "PlayStation"}, {"id": 2, "name": "Nintendo"}]
# First call
result1 = self.igdb.platform_families()
@@ -148,26 +137,14 @@ class TestIGDBQuery(unittest.TestCase):
"""Test platforms method."""
mock_families.return_value = {1: "PlayStation"}
mock_query.return_value = [
{
"id": 1,
"name": "PlayStation 5",
"alternative_name": "PS5",
"abbreviation": "PS5",
"platform_family": 1
},
{
"id": 2,
"name": "Nintendo Switch"
}
{"id": 1, "name": "PlayStation 5", "alternative_name": "PS5", "abbreviation": "PS5", "platform_family": 1},
{"id": 2, "name": "Nintendo Switch"},
]
result = self.igdb.platforms()
self.igdb.platforms()
# Test passes if no exception is raised
expected = {
1: {"names": ["PlayStation 5", "PS5", "PS5"], "family": "PlayStation"},
2: {"names": ["Nintendo Switch"], "family": None}
}
mock_query.assert_called_once_with(
{}, "platforms", ["id", "name", "alternative_name", "abbreviation", "platform_family"], limit=500
)
@@ -180,15 +157,22 @@ class TestIGDBQuery(unittest.TestCase):
result = self.igdb.game_info("Mario")
expected_fields = [
"id", "name", "alternative_names", "category", "release_dates",
"franchise", "language_supports", "keywords", "platforms", "rating", "summary"
"id",
"name",
"alternative_names",
"category",
"release_dates",
"franchise",
"language_supports",
"keywords",
"platforms",
"rating",
"summary",
]
mock_query.assert_called_once_with(
{"name": "Mario"}, "games", expected_fields, limit=100
)
mock_query.assert_called_once_with({"name": "Mario"}, "games", expected_fields, limit=100)
self.assertEqual(result, [{"id": 1, "name": "Super Mario Bros"}])
if __name__ == "__main__":
unittest.main()
unittest.main()