Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Python Integration Tests
Commits
8a9c9602
Verified
Commit
8a9c9602
authored
Dec 14, 2022
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: file storage refactoring: link
parent
0db1530b
No related branches found
No related tags found
1 merge request
!52
Draft: ENH: file system: link
Pipeline
#31789
failed
Dec 14, 2022
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
1
Pipelines
3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_file.py
+114
-6
114 additions, 6 deletions
tests/test_file.py
with
114 additions
and
6 deletions
tests/test_file.py
+
114
−
6
View file @
8a9c9602
...
...
@@ -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/
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment