Skip to content
Snippets Groups Projects
Verified Commit 8a9c9602 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: file storage refactoring: link

parent 0db1530b
No related branches found
No related tags found
1 merge request!52Draft: ENH: file system: link
Pipeline #31789 failed
......@@ -59,12 +59,6 @@ def teardown_function(function):
d = execute_query("FIND ENTITY WHICH HAS AN ID >= 100")
if len(d) > 0:
d.delete()
try:
path = get_config().get("IntegrationTests",
"test_files.test_insert_files_in_dir.local") + "testfolder/"
shutil.rmtree(path)
except Exception as e:
print(e)
try:
shutil.rmtree("testfolder")
except Exception as e:
......@@ -521,3 +515,117 @@ def test_insert_without_auto_create_parent_dirs():
with raises(TransactionError) as exc:
db.Directory(path="A/B").insert(flags={"autoCreateDirs":
"false"})
def test_insert_link():
with open("test.dat", "w") as upload_file:
upload_file.write("hello world\n")
file_ = db.File(name="TestLink1",
description="Testfile Desc",
path="debug/test_link_target",
file="test.dat")
file_.insert()
l = db.Link(path="debug/test_link", target=file_.id)
assert l.link_target is not None
assert str(l.link_target) == str(file_.id)
l.insert()
assert l.link_target is not None
assert str(l.link_target) == str(file_.id)
assert len(execute_query("FIND ENTITY")) == 3 # Directory, File, Link
assert execute_query("FIND LINK WHICH IS STORED AT 'debug/*'",
unique=True).id == l.id
assert execute_query("FIND LINK WHICH IS STORED AT 'debug/test_link'",
unique=True).id == l.id
assert len(execute_query("FIND LINK WHICH IS STORED AT 'debug/test_link_target'")) == 0
l2 = execute_query("FIND LINK", unique=True)
assert l2.id == l.id
assert l2.link_target is not None
assert str(l2.link_target) == str(l.link_target)
assert str(l2.link_target) == str(file_.id)
def test_link_to_file_in_file_system_view():
file_content = "hello world\n"
with open("test.dat", "w") as upload_file:
upload_file.write(file_content)
file_ = db.File(name="TestLink1",
description="Testfile Desc",
path="debug/test_link_target",
file="test.dat")
file_.insert()
l = db.Link(path="debug/test_link", target=file_.id)
l.insert()
body = get_connection().retrieve(
entity_uri_segments=[
"FileSystem",
"debug"],
reconnect=True).read()
xml = etree.fromstring(body)
assert len(xml.xpath('/Response/dir')) == 1
dir_debug = xml.xpath('/Response/dir')[0]
assert dir_debug.get("name") == "debug"
assert dir_debug.get("url")[-18:] == "/FileSystem/debug/"
assert len(dir_debug.xpath('dir')) == 0
assert len(dir_debug.xpath('file')) == 1
assert len(dir_debug.xpath('link')) == 1
link = dir_debug.xpath("link")[0]
assert link.get("name") == "test_link"
assert link.get("url")[-27:] == "/FileSystem/debug/test_link"
response = get_connection().retrieve(
entity_uri_segments=[
"FileSystem",
"debug", "test_link"],
reconnect=True)
body = response.read().decode("utf8")
assert body == file_content
def test_link_to_dir_in_file_system_view():
d = db.Directory(path="debug/test_link_target").insert()
l = db.Link(path="debug/test_link", target=d.id)
l.insert()
body = get_connection().retrieve(
entity_uri_segments=[
"FileSystem",
"debug"],
reconnect=True).read()
xml = etree.fromstring(body)
assert len(xml.xpath('/Response/dir')) == 1
dir_debug = xml.xpath('/Response/dir')[0]
assert dir_debug.get("name") == "debug"
assert dir_debug.get("url")[-18:] == "/FileSystem/debug/"
assert len(dir_debug.xpath('dir')) == 1
assert len(dir_debug.xpath('file')) == 0
assert len(dir_debug.xpath('link')) == 1
link = dir_debug.xpath("link")[0]
assert link.get("name") == "test_link"
assert link.get("url")[-27:] == "/FileSystem/debug/test_link"
response = get_connection().retrieve(
entity_uri_segments=[
"FileSystem",
"debug", "test_link"],
reconnect=True)
body = response.read()
print(body.decode())
xml = etree.fromstring(body)
assert len(xml.xpath('/Response/dir')) == 1
dir_link_target = xml.xpath('/Response/dir')[0]
assert dir_link_target.get("name") == "test_link_target"
assert dir_link_target.get("url")[-35:] == "/FileSystem/debug/test_link_target/"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment