-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into github-actions
- Loading branch information
Showing
2 changed files
with
95 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,63 @@ | ||
from server.main import get_base_path, walk_paths, TapisFile | ||
import pytest | ||
import os | ||
from fastapi.exceptions import HTTPException | ||
from server.main import get_system_root, walk_archive_paths | ||
|
||
|
||
def test_get_base_path(): | ||
def test_get_system_root(): | ||
assert ( | ||
get_base_path("designsafe.storage.default", "/path/to/file") | ||
== "/corral-repl/tacc/NHERI/shared/path/to/file" | ||
get_system_root("designsafe.storage.default") | ||
== "/corral-repl/tacc/NHERI/shared" | ||
) | ||
assert ( | ||
get_base_path("designsafe.storage.default", "path/to/file") | ||
== "/corral-repl/tacc/NHERI/shared/path/to/file" | ||
get_system_root("designsafe.storage.community") | ||
== "/corral-repl/tacc/NHERI/community" | ||
) | ||
assert ( | ||
get_base_path("designsafe.storage.community", "/path/to/file") | ||
== "/corral-repl/tacc/NHERI/community/path/to/file" | ||
get_system_root("designsafe.storage.published") | ||
== "/corral-repl/tacc/NHERI/published" | ||
) | ||
assert ( | ||
get_base_path("designsafe.storage.published", "/path/to/file") | ||
== "/corral-repl/tacc/NHERI/published/path/to/file" | ||
get_system_root("project-7448086614930166251-242ac113-0001-012") | ||
== "/corral-repl/tacc/NHERI/projects/7448086614930166251-242ac113-0001-012" | ||
) | ||
assert ( | ||
get_base_path("project-7448086614930166251-242ac113-0001-012", "/path/to/file") | ||
== "/corral-repl/tacc/NHERI/projects/7448086614930166251-242ac113-0001-012/path/to/file" | ||
) | ||
|
||
|
||
def test_walk_paths(tmp_path): | ||
with pytest.raises(HTTPException): | ||
get_system_root("not-a-real-system") | ||
|
||
|
||
def test_walk_archive(tmp_path): | ||
""" | ||
Generate and walk the following directory structure at tmp_path: | ||
. | ||
├── f1.txt | ||
└── sub_path/ | ||
├── f2.txt | ||
└── sub_path2/ | ||
└── f3.txt | ||
""" | ||
base = tmp_path | ||
sub = base / "sub_path" | ||
os.mkdir(sub) | ||
|
||
f1 = base / "f1.txt" | ||
f1.write_text("CONTENT 1") | ||
|
||
sub = base / "sub_path" | ||
os.mkdir(sub) | ||
f2 = sub / "f2.txt" | ||
f2.write_text("CONTENT 2") | ||
|
||
requested_files = [ | ||
TapisFile(**{ | ||
"path": "", | ||
"type": "folder" | ||
}) | ||
sub2 = sub / "sub_path2" | ||
os.mkdir(sub2) | ||
f3 = sub2 / "f3.txt" | ||
f3.write_text("CONTENT 3") | ||
|
||
requested_files = ["f1.txt", "sub_path"] | ||
walk_result = walk_archive_paths(base, requested_files) | ||
|
||
assert walk_result == [ | ||
{"fs": str(base / "f1.txt"), "n": "f1.txt"}, | ||
{"fs": str(base / "sub_path" / "f2.txt"), "n": "sub_path/f2.txt"}, | ||
{ | ||
"fs": str(base / "sub_path" / "sub_path2" / "f3.txt"), | ||
"n": "sub_path/sub_path2/f3.txt", | ||
}, | ||
] | ||
|
||
paths2 = walk_paths(base, requested_files) | ||
assert paths2 == [ | ||
{'fs': str(base / "f1.txt"), 'n': 'f1.txt'}, | ||
{'fs': str(base / "sub_path" / "f2.txt"), 'n': "sub_path/f2.txt"} | ||
] | ||
|