32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
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()
|