This commit is contained in:
1 parent
b65c8c39fe
commit
b2ab347129
18 files changed
+166
-25
No files matched your search
@@ -102,6 +102,8 @@ class ApiTests(unittest.TestCase):
|
||||
"""INSERT INTO game_translations (appid, lang, short_description, provider, translated_at)
|
||||
VALUES (1, 'ru', 'Кратко', 'google', '2026-01-01')""")
|
||||
con.execute("INSERT INTO attributes (appid, key, value) VALUES (1, 'mood', 'calm')")
|
||||
con.execute("""UPDATE games SET estimated_hours = CASE appid
|
||||
WHEN 1 THEN 30 WHEN 2 THEN 10 WHEN 3 THEN 5 ELSE NULL END""")
|
||||
con.commit()
|
||||
|
||||
def get(self, path, expect=200):
|
||||
@@ -171,6 +173,7 @@ class ApiTests(unittest.TestCase):
|
||||
self.assertEqual(alpha["year"], 2020)
|
||||
self.assertEqual(alpha["review"], 90)
|
||||
self.assertEqual(alpha["hours"], 2.0)
|
||||
self.assertEqual(alpha["duration"], 30)
|
||||
self.assertTrue(alpha["installed"])
|
||||
self.assertEqual(alpha["status"], "playing")
|
||||
self.assertEqual(alpha["rating"], 9)
|
||||
@@ -231,6 +234,9 @@ class ApiTests(unittest.TestCase):
|
||||
self.assertEqual(ids("/api/games?max_review=85"), {2, 3})
|
||||
self.assertEqual(ids("/api/games?min_review=80&max_hours=1"), {2})
|
||||
self.assertEqual(ids("/api/games?min_hours=oops&min_review="), {1, 2, 3})
|
||||
self.assertEqual(ids("/api/games?duration=short"), {3})
|
||||
self.assertEqual(ids("/api/games?duration=medium"), {2})
|
||||
self.assertEqual(ids("/api/games?duration=long"), {1})
|
||||
self.assertEqual(server.number_param({"x": ["bad"]}, "x", int), None)
|
||||
self.assertEqual(server.number_param({"x": ["7"]}, "x", int), 7)
|
||||
|
||||
@@ -242,6 +248,7 @@ class ApiTests(unittest.TestCase):
|
||||
def test_games_sort_and_pagination(self):
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?sort=review")["items"]], [1, 2, 3])
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?sort=hours")["items"]], [1, 3, 2])
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?sort=duration")["items"]], [3, 2, 1])
|
||||
page2 = self.get("/api/games?per_page=12&page=2")
|
||||
self.assertEqual(page2["page"], 2)
|
||||
self.assertEqual(page2["items"], [])
|
||||
|
||||
@@ -67,6 +67,7 @@ class SchemaVersionTests(unittest.TestCase):
|
||||
self.assertIn("game_translations", tables)
|
||||
self.assertIn("reco_feedback", tables)
|
||||
self.assertIn("game_fts", tables)
|
||||
self.assertIn("estimated_hours", self._columns(con, "games"))
|
||||
|
||||
def test_legacy_database_is_migrated_and_data_preserved(self):
|
||||
con = sqlite3.connect(self.path)
|
||||
@@ -87,6 +88,7 @@ class SchemaVersionTests(unittest.TestCase):
|
||||
details = con.execute("SELECT short_description, source_appid FROM game_details WHERE appid=100").fetchone()
|
||||
self.assertEqual(details["short_description"], "Old description")
|
||||
self.assertIsNone(details["source_appid"])
|
||||
self.assertIn("estimated_hours", self._columns(con, "games"))
|
||||
fts_tables = {r[0] for r in con.execute(
|
||||
"SELECT name FROM sqlite_master WHERE name='game_fts'")}
|
||||
self.assertEqual(fts_tables, {"game_fts"})
|
||||
@@ -103,6 +105,15 @@ class SchemaVersionTests(unittest.TestCase):
|
||||
self.assertEqual(self._version(con), str(db.SCHEMA_VERSION))
|
||||
self.assertEqual(con.execute("SELECT COUNT(*) c FROM games").fetchone()["c"], 1)
|
||||
|
||||
def test_duration_estimate(self):
|
||||
self.assertEqual(db.estimate_hours({"RPG"}, set()), 30)
|
||||
self.assertEqual(db.estimate_hours({"RPG"}, {"Short"}), 5)
|
||||
self.assertEqual(db.estimate_hours({"Adventure"}, {"Open World", "Short"}), 5)
|
||||
self.assertEqual(db.estimate_hours(set(), {"City Builder"}), 28)
|
||||
self.assertEqual(db.estimate_hours(set(), {"MMORPG"}), 80)
|
||||
self.assertEqual(db.estimate_hours(set(), set()), 12)
|
||||
self.assertEqual(db.estimate_hours({"Casual"}, set()), 6)
|
||||
|
||||
def test_search_index_rebuild_and_single_game_refresh(self):
|
||||
con = db.connect(self.path)
|
||||
self.addCleanup(con.close)
|
||||
|
||||
@@ -127,6 +127,8 @@ class ImportSteamTests(unittest.TestCase):
|
||||
hits = [r[0] for r in con.execute(
|
||||
"SELECT appid FROM game_fts WHERE game_fts MATCH 'alpha*'")]
|
||||
self.assertEqual(hits, [100])
|
||||
self.assertEqual(alpha["estimated_hours"], 30)
|
||||
self.assertEqual(self._game(con, 200)["estimated_hours"], 8)
|
||||
|
||||
def test_incremental_keeps_metadata_and_preserves_personal(self):
|
||||
con = self._run({100: game_info("Old Name", review=80)})
|
||||
|
||||
Reference in new issue
Block a user