init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
if str(TOOLS) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS))
|
||||
|
||||
import _common
|
||||
from new_project import release_files
|
||||
|
||||
|
||||
class ChannelLayoutTest(unittest.TestCase):
|
||||
def test_tree_root_is_already_channel_scoped(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
_common.set_tree_root(root, channel="a" * 32)
|
||||
self.assertEqual(_common.CAMPAIGN_DIR, root.resolve() / "web")
|
||||
self.assertEqual(_common.SYNC_DIR, root.resolve() / "sync")
|
||||
|
||||
def test_release_manifest_files_are_relative_and_hashed(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
(root / "web").mkdir()
|
||||
(root / "sync").mkdir()
|
||||
(root / "web" / "support.html").write_bytes(b"support")
|
||||
(root / "sync" / "daily.html").write_bytes(b"daily")
|
||||
|
||||
files = release_files(root)
|
||||
|
||||
self.assertEqual(
|
||||
[item["path"] for item in files],
|
||||
["web/support.html", "sync/daily.html"],
|
||||
)
|
||||
self.assertTrue(all(len(str(item["sha256"])) == 64 for item in files))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,62 @@
|
||||
import json
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
if str(TOOLS) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS))
|
||||
|
||||
from patch_core import update_daily_hashes
|
||||
|
||||
|
||||
class UpdateDailyHashesTest(unittest.TestCase):
|
||||
def test_rewrites_all_urls_to_channel_sync_path(self) -> None:
|
||||
channel = "a" * 32
|
||||
source = {
|
||||
"core": {
|
||||
"url": "http://[HOST_PLACEHOLDER]/sync/erupt_flee.js",
|
||||
"sha256": "old",
|
||||
"size": 1,
|
||||
},
|
||||
"springboard_entries": [
|
||||
{
|
||||
"url": "http://[HOST_PLACEHOLDER]/sync/spring.js",
|
||||
"sha256": "old",
|
||||
"size": 2,
|
||||
}
|
||||
],
|
||||
"entries": [
|
||||
{
|
||||
"url": "http://[HOST_PLACEHOLDER]/sync/entry.js",
|
||||
"sha256": "old",
|
||||
"size": 3,
|
||||
}
|
||||
],
|
||||
}
|
||||
hashes = {
|
||||
"erupt_flee.js": ("core-hash", 10),
|
||||
"spring.js": ("spring-hash", 20),
|
||||
"entry.js": ("entry-hash", 30),
|
||||
}
|
||||
|
||||
result = json.loads(
|
||||
update_daily_hashes(
|
||||
json.dumps(source).encode(),
|
||||
hashes,
|
||||
channel=channel,
|
||||
)
|
||||
)
|
||||
|
||||
prefix = f"http://[HOST_PLACEHOLDER]/channel/{channel}/sync/"
|
||||
self.assertEqual(result["core"]["url"], prefix + "erupt_flee.js")
|
||||
self.assertEqual(result["core"]["sha256"], "core-hash")
|
||||
self.assertEqual(result["springboard_entries"][0]["url"], prefix + "spring.js")
|
||||
self.assertEqual(result["springboard_entries"][0]["size"], 20)
|
||||
self.assertEqual(result["entries"][0]["url"], prefix + "entry.js")
|
||||
self.assertNotIn("/sync/", json.dumps(result).replace(f"/channel/{channel}/sync/", ""))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user