47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Tests for series/tag scope selection."""
|
|
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.join(ROOT, "tools"))
|
|
sys.path.insert(0, os.path.join(ROOT, "web"))
|
|
|
|
import db
|
|
import server
|
|
|
|
|
|
class ScopeTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.con = db.connect(os.path.join(self.tmp.name, "scope.db"))
|
|
self.addCleanup(self.con.close)
|
|
db.init(self.con)
|
|
self.con.executemany(
|
|
"INSERT INTO games (appid, name, type) VALUES (?, ?, 'game')",
|
|
[(1, "Portal",), (2, "Portal 2",), (3, "Portal Stories: Mel",),
|
|
(4, "Other Game",)])
|
|
self.con.executemany(
|
|
"INSERT INTO game_tags (appid, tag_id) VALUES (?, ?)",
|
|
[(1, 10), (2, 10), (4, 10)])
|
|
self.con.execute("INSERT INTO tag_names (tag_id, name) VALUES (10, 'Roguelike')")
|
|
self.con.commit()
|
|
|
|
def test_series_scope(self):
|
|
self.assertEqual(set(server.scope_appids(self.con, "series", appid=1)), {1, 2})
|
|
self.assertIsNone(server.scope_appids(self.con, "series", appid=999))
|
|
|
|
def test_tag_scope(self):
|
|
self.assertEqual(set(server.scope_appids(self.con, "tag", tag="roguelike")),
|
|
{1, 2, 4})
|
|
self.assertEqual(server.scope_appids(self.con, "tag", tag="Missing"), [])
|
|
self.assertIsNone(server.scope_appids(self.con, "tag", tag=""))
|
|
self.assertIsNone(server.scope_appids(self.con, "unknown"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|