Files

61 lines
2.6 KiB
Python

import os, sys, unittest
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
sys.path.insert(0, os.path.join(ROOT, "scripts"))
from update_swarm.judge import judge_one
def job(**kw):
base = {"stem": "X", "watchlist": False, "wanted": False, "note_version": None}
base.update(kw)
return base
def census(**kw):
base = {"stem": "X", "installed_version": "1.0", "source": "file", "sha256": "aa"}
base.update(kw)
return base
def scout(**kw):
base = {"stem": "X", "latest_english_version": "1.1", "url": "https://github.com/a/b/releases/download/v1.1/x.zip",
"host": "github", "gate": "ungated", "upstream_status": "Complete", "sha256": None}
base.update(kw)
return base
class TestJudge(unittest.TestCase):
def test_update_ungated(self):
v = judge_one(job(), census(), scout())
self.assertEqual(v["bucket"], "update")
self.assertEqual(v["fetch_url"], scout()["url"])
def test_current_when_installed_newer_or_equal(self):
v = judge_one(job(), census(installed_version="1.1"), scout())
self.assertEqual(v["bucket"], "current")
def test_gated_queue_and_complete_bump(self):
v = judge_one(job(), census(), scout(gate="gated", url="https://foo.itch.io/x"))
self.assertEqual(v["bucket"], "gated_queue")
self.assertEqual(v["bump_status"], "Complete")
self.assertIsNone(v["fetch_url"])
def test_watchlist_promote_and_report(self):
p = judge_one(job(watchlist=True), census(), scout(upstream_status="Complete"))
self.assertEqual(p["bucket"], "watchlist_promote")
self.assertTrue(p["remove_from_watchlist"])
r = judge_one(job(watchlist=True), census(), scout(upstream_status="Beta"))
self.assertEqual(r["bucket"], "watchlist_report")
self.assertFalse(r["remove_from_watchlist"])
def test_watchlist_complete_but_gated_is_queue(self):
v = judge_one(job(watchlist=True), census(), scout(gate="gated", url="https://foo.itch.io/x"))
self.assertEqual(v["bucket"], "gated_queue")
def test_no_latest_and_incomparable(self):
self.assertEqual(judge_one(job(), census(), scout(latest_english_version=None))["bucket"], "current")
self.assertEqual(judge_one(job(), census(installed_version="Final"), scout())["bucket"], "incomparable")
def test_unknown_installed_hash_match(self):
v = judge_one(job(), census(installed_version=None, source="unknown", sha256="dead"),
scout(sha256="dead"))
self.assertEqual(v["bucket"], "current")
if __name__ == "__main__":
unittest.main()