46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
import json, os, sys, tempfile, unittest
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
sys.path.insert(0, os.path.join(ROOT, "scripts"))
|
|
from update_swarm.cli import deploy_argv, validate_scout
|
|
from update_swarm.reports import write_reports
|
|
|
|
class TestCli(unittest.TestCase):
|
|
def test_validate_scout_missing_keys(self):
|
|
errs = validate_scout({"stem": "Z"})
|
|
self.assertIn("latest_english_version", " ".join(errs))
|
|
|
|
def test_validate_scout_ok(self):
|
|
obj = {
|
|
"stem": "Z", "latest_english_version": "2.13", "url": "https://example.com/z.zip",
|
|
"host": "other", "gate": "gated", "language_matrix": {"en": "2.13", "es": "2.18"},
|
|
"source_used": "website", "hackdex": "skipped", "upstream_status": "Complete", "notes": "",
|
|
}
|
|
self.assertEqual(validate_scout(obj), [])
|
|
|
|
def test_reports(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
verdicts = [
|
|
{"stem": "A", "bucket": "gated_queue", "latest_english_version": "2.0", "fetch_url": None, "gate": "itch", "reason": "newer-gated"},
|
|
{"stem": "B", "bucket": "watchlist_report", "latest_english_version": "0.7", "reason": "watchlist-demo"},
|
|
]
|
|
write_reports(td, verdicts)
|
|
gated = open(os.path.join(td, "gated.md"), encoding="utf-8").read()
|
|
wl = open(os.path.join(td, "watchlist-report.md"), encoding="utf-8").read()
|
|
self.assertIn("A", gated)
|
|
self.assertIn("B", wl)
|
|
|
|
def test_deploy_argv(self):
|
|
cmds = deploy_argv("/pokemon", "/site")
|
|
self.assertEqual(cmds[0], ["python", "scripts/build-vault-mocs.py"])
|
|
self.assertEqual(cmds[1], ["python", "scripts/build-wiki-data.py"])
|
|
self.assertEqual(cmds[2][-1], "scripts/deploy-site.ps1")
|
|
|
|
def test_prompt_file_exists(self):
|
|
path = os.path.join(ROOT, "scripts", "update_swarm", "scout_prompt.md")
|
|
text = open(path, encoding="utf-8").read()
|
|
self.assertIn("latest_english_version", text)
|
|
self.assertIn("Do not invent versions", text)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|