blob: 05a4af7475bd07c8c39780119301704a91aa832d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
"""
Every way a file is saved goes through a name that can be written everywhere
(docs/MESHBAY_DESIGN.md §10, `static/portable-name.js`).
The rule itself is held to Python's by `test_portable_name_parity.py`. What this
holds is that the save paths use it: a single file under `portableName`, the
entries of a folder's zip and the archive's own name under `portablePath` /
`portableName`, and the node's own name never handed to a save target directly.
Read from the source, because these paths need a browser and a disk to run.
"""
import re
from pathlib import Path
STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"
FILE_UTILS = (STATIC / "file-utils.js").read_text(encoding="utf-8")
def _body(name: str) -> str:
m = re.search(rf"^async function {name}\(.*?^\}}", FILE_UTILS, re.M | re.S)
assert m, f"file-utils.js no longer has {name}"
return m.group(0)
def test_a_single_file_is_saved_under_a_portable_name():
body = _body("downloadEntry")
assert "portableName(entry.name)" in body
assert "_openTargetInTurn(saveName" in body
assert "_saveBlob(blob, saveName)" in body
assert "_openTargetInTurn(entry.name" not in body
assert "_saveBlob(blob, entry.name)" not in body
def test_a_zip_writes_portable_names_and_is_named_portably():
body = _body("downloadDirectory")
assert "zip.begin(portablePath(name)" in body
assert "portableName(dir.split('/').pop()" in body
def test_a_renamed_file_is_said_so_on_its_row():
assert "t('transfers.renamed'" in _body("downloadEntry")
assert "t('transfers.renamed_n'" in _body("downloadDirectory")
|