fix: 校验独立站公开快照并补充自托管说明

This commit is contained in:
Jack
2026-08-17 21:21:06 +08:00
parent 7af253f081
commit 92ddb84246
13 changed files with 323 additions and 11 deletions
+31
View File
@@ -0,0 +1,31 @@
import json
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from scripts.verify_public_snapshot import check_url
class VerifyPublicSnapshotTests(unittest.TestCase):
def test_public_snapshot_must_match_generated_at_and_as_of_date(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "textile-intelligence.json"
path.write_text(json.dumps({"generated_at": "2026-08-17T12:30:21Z", "as_of_date": "2026-08-17"}), encoding="utf-8")
class Response:
def __enter__(self):
return self
def __exit__(self, *args):
return False
def read(self):
return b'{"generated_at":"2026-08-17T12:30:21Z","as_of_date":"2026-08-17"}'
with patch("scripts.verify_public_snapshot.urlopen", return_value=Response()):
self.assertEqual(check_url("https://example.test", "/data/textile-intelligence.json", path), ("2026-08-17T12:30:21Z", "2026-08-17"))
if __name__ == "__main__":
unittest.main()