Files
pokemon/tests/update_swarm/test_hosts.py
T
ginnoir cb294f72a0 fix: address whole-branch review findings for update-swarm
- versions: require entire normalized string to be numeric so dates
  and hotfix suffixes compare as incomparable instead of eq/gt
- hosts: exact host or dot-suffix match rejects lookalikes like
  notmediafire.com and evilmega.nz; GitHub stays exact-set
- census: lazy extractor loop so a later OSError no longer discards an
  earlier sidecar changelog hit
- jobs: watchlist parses only table rows whose vault-note cell is a
  bare wikilink (skips parenthetical related/complete notes); wanted
  also matches bold names in Wanted.md tables with Pokemon prefix
  stripped and casefolded
- cli: validate-scouts and judge raise SystemExit when jobs.json has
  jobs but scouts/ has zero valid files
- fetch: download forwards timeout=60 to urlopen and writes to a
  .part file then os.replace, removing the partial on any failure
2026-08-14 15:11:16 -05:00

36 lines
2.2 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.hosts import classify_url
class TestClassify(unittest.TestCase):
def test_ungated(self):
self.assertEqual(classify_url("https://github.com/a/b/releases/download/v1/x.gba"), ("github", "ungated"))
self.assertEqual(classify_url("https://archive.org/download/id/file.gba"), ("archive", "ungated"))
self.assertEqual(classify_url("https://www.mediafire.com/file/abc/x.zip/file"), ("mediafire", "ungated"))
self.assertEqual(classify_url("https://mega.nz/file/abc#keyfragment"), ("mega", "ungated"))
def test_gated(self):
self.assertEqual(classify_url("https://mega.nz/file/abc"), ("mega", "gated"))
self.assertEqual(classify_url("https://foo.itch.io/bar"), ("itch", "gated"))
self.assertEqual(classify_url("https://drive.google.com/file/d/x/view"), ("drive", "gated"))
self.assertEqual(classify_url("https://discord.gg/abc"), ("discord", "gated"))
self.assertEqual(classify_url("https://ko-fi.com/s/abc"), ("kofi", "gated"))
self.assertEqual(classify_url("https://hackdex.app/hack/x"), ("hackdex", "gated"))
self.assertEqual(classify_url("https://www.pokecommunity.com/threads/x.1/"), ("pokecommunity", "gated"))
self.assertEqual(classify_url("https://mystery.example/file.zip"), ("other", "gated"))
def test_lookalike_hosts_are_gated(self):
self.assertEqual(classify_url("https://notmediafire.com/x"), ("other", "gated"))
self.assertEqual(classify_url("https://evilmega.nz/file/a#k"), ("other", "gated"))
self.assertEqual(classify_url("https://notarchive.org/x"), ("other", "gated"))
self.assertEqual(classify_url("https://notitch.io/x"), ("other", "gated"))
def test_real_hosts_still_classified(self):
self.assertEqual(classify_url("https://www.mediafire.com/file/abc/x.zip/file"), ("mediafire", "ungated"))
self.assertEqual(classify_url("https://mega.nz/file/a#k"), ("mega", "ungated"))
self.assertEqual(classify_url("https://sub.archive.org/download/x"), ("archive", "ungated"))
if __name__ == "__main__":
unittest.main()