feat: distinguish owned and shared games
CI / test (push) Successful in 40s

Add game_ownership (schema v10) and tools/check_ownership.py, compare the local library with GetOwnedGames, expose owned/shared counts and filters, and show a shared-game badge on cards.
This commit is contained in:
strsv committed 2026-11-07 01:40:47 +03:00
1 parent 528fcb7474
commit 2ed00b7912
18 files changed
+255 -10

No files matched your search

+13
View File
@@ -80,6 +80,10 @@ class ApiTests(unittest.TestCase):
con.execute("INSERT INTO games (appid, name, type, parent_appid) "
"VALUES (5, 'Alpha DLC', 'dlc', 1)")
con.execute("INSERT INTO game_playtime (appid, minutes) VALUES (5, 0)")
con.execute("INSERT INTO game_ownership (appid, owned, checked_at) "
"VALUES (1, 1, '2026-01-01')")
con.execute("INSERT INTO game_ownership (appid, owned, checked_at) "
"VALUES (2, 0, '2026-01-01')")
installs = [(1, 1, 1024 * 1024 * 1024, "C:/Steam"), (2, 0, None, None)]
con.executemany(
"INSERT INTO game_install (appid, installed, size_bytes, library_path) VALUES (?,?,?,?)",
@@ -184,6 +188,8 @@ class ApiTests(unittest.TestCase):
self.assertEqual(data["signals"], 1)
self.assertEqual(data["hltb_checked"], 2)
self.assertEqual(data["hltb_matched"], 1)
self.assertEqual(data["owned"], 1)
self.assertEqual(data["shared"], 1)
self.assertFalse(data["steam_api"])
genres = {g["name"]: g["count"] for g in data["genres"]}
self.assertEqual(genres["RPG"], 2)
@@ -494,6 +500,13 @@ class ApiTests(unittest.TestCase):
finally:
con.close()
def test_ownership_filter_and_card(self):
self.assertEqual([g["appid"] for g in self.get("/api/games?ownership=owned")["items"]], [1])
self.assertEqual([g["appid"] for g in self.get("/api/games?ownership=shared")["items"]], [2])
self.assertEqual(self.get("/api/game/1")["owned"], 1)
self.assertEqual(self.get("/api/game/2")["owned"], 0)
self.assertIsNone(self.get("/api/game/3")["owned"])
def test_game_addons_and_parent(self):
game = self.get("/api/game/1")
self.assertEqual(game["addons"], [
+68
View File
@@ -0,0 +1,68 @@
"""Tests for the Steam ownership marker."""
import contextlib
import io
import os
import sys
import tempfile
import unittest
from unittest import mock
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(ROOT, "tools"))
import check_ownership
import db
class OwnershipTests(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.addCleanup(self.tmp.cleanup)
self.path = os.path.join(self.tmp.name, "own.db")
con = db.connect(self.path)
db.init(con)
con.executemany(
"INSERT INTO games (appid, name, type) VALUES (?,?,?)",
[(1, "A", "game"), (2, "B", "game"), (3, "C", "dlc")])
con.commit()
con.close()
def _run(self, *extra):
argv = ["check_ownership.py", "--db", self.path, *extra]
with mock.patch.object(sys, "argv", argv), \
mock.patch.object(check_ownership.steam_api, "has_key", return_value=True), \
mock.patch.object(check_ownership.steam_api, "steam_id", return_value="765"), \
mock.patch.object(check_ownership.steam_api, "owned_games",
return_value=[{"appid": 1}, {"appid": 3}]), \
contextlib.redirect_stdout(io.StringIO()):
return check_ownership.main()
def test_marks_owned_and_shared(self):
self.assertEqual(self._run(), 0)
con = db.connect(self.path)
try:
rows = {row["appid"]: row["owned"] for row in con.execute(
"SELECT appid, owned FROM game_ownership")}
finally:
con.close()
self.assertEqual(rows, {1: 1, 2: 0})
def test_dry_run_does_not_write(self):
self.assertEqual(self._run("--dry-run"), 0)
con = db.connect(self.path)
try:
count = con.execute("SELECT COUNT(*) FROM game_ownership").fetchone()[0]
finally:
con.close()
self.assertEqual(count, 0)
def test_requires_key(self):
with mock.patch.object(check_ownership.steam_api, "has_key", return_value=False), \
mock.patch.object(sys, "argv", ["check_ownership.py", "--db", self.path]), \
contextlib.redirect_stderr(io.StringIO()):
self.assertEqual(check_ownership.main(), 1)
if __name__ == "__main__":
unittest.main()