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
d0401750
Verified
Commit
d0401750
authored
Jun 24, 2022
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for file import
parent
57498fda
No related branches found
No related tags found
1 merge request
!53
Draft: ENH: file system: import
Pipeline
#24704
failed
Jun 24, 2022
Stage: info
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
+149
-46
149 additions, 46 deletions
tests/test_file.py
with
149 additions
and
46 deletions
tests/test_file.py
+
149
−
46
View file @
d0401750
...
@@ -189,36 +189,6 @@ def test_file4():
...
@@ -189,36 +189,6 @@ def test_file4():
pass
pass
def
test_upload_complete_folder
():
file1_
=
models
.
File
(
name
=
"
Testfile1
"
,
description
=
"
Testfile Desc
"
,
path
=
"
testfiles/testfile1.dat
"
+
hex
(
randint
(
0
,
maxint
)),
file
=
"
test.dat
"
)
file2_
=
models
.
File
(
name
=
"
Testfile2
"
,
description
=
"
Testfile Desc
"
,
path
=
"
testfiles/testfile2.dat
"
+
hex
(
randint
(
0
,
maxint
)),
file
=
"
test.dat
"
)
c
=
models
.
Container
()
c
.
extend
([
file1_
,
file2_
])
c
.
insert
()
assert
file1_
.
id
is
not
None
assert
file2_
.
id
is
not
None
c
.
delete
()
c
=
models
.
Container
()
folder_
=
models
.
File
(
name
=
"
Testfolder
"
,
description
=
"
Testfolder Desc
"
,
path
=
"
testfiles/testfolder
"
+
hex
(
randint
(
0
,
maxint
)),
file
=
"
testfolder
"
)
c
.
append
(
folder_
)
c
.
insert
()
assert
folder_
.
id
is
not
None
c
.
delete
()
def
test_file6
():
def
test_file6
():
try
:
try
:
# upload file to testfiles2/testfile...
# upload file to testfiles2/testfile...
...
@@ -674,7 +644,6 @@ def test_insert_files_in_dir_regex():
...
@@ -674,7 +644,6 @@ def test_insert_files_in_dir_regex():
pass
pass
@mark.xfail
(
reason
=
"
Needs file system refactoring
"
)
def
test_auto_create_parent_dirs
():
def
test_auto_create_parent_dirs
():
file_
=
models
.
File
(
name
=
"
TestFile
"
,
file_
=
models
.
File
(
name
=
"
TestFile
"
,
path
=
"
A/B/C/test.dat
"
,
path
=
"
A/B/C/test.dat
"
,
...
@@ -755,38 +724,128 @@ def test_auto_create_parent_dirs():
...
@@ -755,38 +724,128 @@ def test_auto_create_parent_dirs():
assert
file_1
.
get
(
"
url
"
)[
-
26
:]
==
"
/FileSystem/A/B/C/test.dat
"
assert
file_1
.
get
(
"
url
"
)[
-
26
:]
==
"
/FileSystem/A/B/C/test.dat
"
@mark.xfail
(
reason
=
"
Needs file system refactoring
"
)
def
test_import_file
():
def
test_import_file
():
downloaded_file
=
None
path
=
get_config
().
get
(
"
IntegrationTests
"
,
path
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
try
:
try
:
os
.
makedirs
(
path
)
os
.
makedirs
(
path
)
os
.
makedirs
(
path
+
"
subfolder/
"
)
os
.
makedirs
(
path
+
"
subfolder/
"
)
with
open
(
path
+
"
subfolder/some_data.csv
"
,
"
w
"
)
as
test_file1
:
local_file
=
os
.
path
.
join
(
path
,
"
subfolder
"
,
"
some_data.csv
"
)
with
open
(
local_file
,
"
w
"
)
as
test_file1
:
test_file1
.
write
(
"
hello, world
\n
"
)
test_file1
.
write
(
"
hello, world
\n
"
)
checksum
=
db
.
File
.
sha512
(
local_file
)
file_
=
db
.
File
(
description
=
"
Testfile Desc
"
,
file_
=
db
.
File
(
import_file
=
True
,
# server knows where to look
import_file
=
True
,
path
=
"
testfolder/subfolder/some_data.csv
"
)
path
=
"
subfolder/some_data.csv
"
)
file_
.
checksum
=
checksum
file_
.
insert
()
file_
.
insert
()
file_
=
db
.
File
(
description
=
"
Testfile Desc
"
,
re
=
db
.
execute_query
(
"
FIND FILE WHICH IS STORED AT /testfolder/subfolder/some_data.csv
"
,
unique
=
True
)
import_file
=
True
,
assert
re
.
id
==
file_
.
id
path
=
"
subfolder/some_data.csv
"
)
assert
re
.
checksum
==
checksum
downloaded_file
=
re
.
download
()
assert
db
.
File
.
sha512
(
downloaded_file
)
==
checksum
finally
:
try
:
os
.
remove
(
downloaded_file
)
except
BaseException
:
pass
def
test_import_non_existing_file
():
file_
=
db
.
File
(
import_file
=
True
,
path
=
"
testfolder/subfolder/does_not_exist.csv
"
)
with
raises
(
TransactionError
)
as
te
:
file_
.
insert
()
file_
.
insert
()
cm
=
te
.
value
.
errors
[
0
]
errors
=
cm
.
entity
.
get_errors
()
assert
errors
[
0
].
description
==
'
This file does not exist. It cannot be imported.
'
def
test_import_checksum_mismatch
():
path
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
try
:
os
.
makedirs
(
path
)
os
.
makedirs
(
path
+
"
subfolder/
"
)
local_file
=
os
.
path
.
join
(
path
,
"
subfolder
"
,
"
some_data.csv
"
)
with
open
(
local_file
,
"
w
"
)
as
test_file1
:
test_file1
.
write
(
"
hello, world
\n
"
)
file_
=
db
.
File
(
import_file
=
True
,
# server knows where to look
path
=
"
testfolder/subfolder/some_data.csv
"
)
file_
.
checksum
=
"
abc123
"
# this is a wrong checksum
with
raises
(
TransactionError
)
as
te
:
file_
.
insert
()
cm
=
te
.
value
.
errors
[
0
]
errors
=
cm
.
entity
.
get_errors
()
assert
errors
[
0
].
description
==
'
Checksum test failed. File is corrupted.
'
file_
.
delete
()
finally
:
finally
:
# we need to delete this one manually, bc file_.delete() will not
# delete the file
try
:
try
:
shutil
.
rmtree
(
path
)
shutil
.
rmtree
(
path
)
except
BaseException
:
except
BaseException
:
pass
pass
@mark.xfail
(
reason
=
"
Needs file system refactoring
"
)
def
test_import_existing
():
path
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
os
.
makedirs
(
path
)
os
.
makedirs
(
path
+
"
subfolder/
"
)
local_file
=
os
.
path
.
join
(
path
,
"
subfolder
"
,
"
some_data.csv
"
)
with
open
(
local_file
,
"
w
"
)
as
test_file1
:
test_file1
.
write
(
"
hello, world
\n
"
)
file_
=
db
.
File
(
import_file
=
True
,
path
=
"
testfolder/subfolder/some_data.csv
"
)
# insert once
file_
.
insert
()
# insert again
file2
=
db
.
File
(
import_file
=
True
,
path
=
"
testfolder/subfolder/some_data.csv
"
)
with
raises
(
TransactionError
)
as
te
:
file2
.
insert
()
cm
=
te
.
value
.
errors
[
0
]
errors
=
cm
.
entity
.
get_errors
()
assert
errors
[
0
].
description
==
'
This target path does already exist.
'
def
test_import_creates_parents
():
path
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
os
.
makedirs
(
path
)
os
.
makedirs
(
path
+
"
subfolder/
"
)
local_file
=
os
.
path
.
join
(
path
,
"
subfolder
"
,
"
some_data.csv
"
)
with
open
(
local_file
,
"
w
"
)
as
test_file1
:
test_file1
.
write
(
"
hello, world
\n
"
)
file_
=
db
.
File
(
import_file
=
True
,
path
=
"
testfolder/subfolder/some_data.csv
"
)
file_
.
insert
()
re
=
db
.
execute_query
(
"
FIND Entity WHICH IS STORED AT /testfolder/subfolder*
"
)
for
e
in
re
:
if
e
.
role
==
"
Directory
"
:
assert
e
.
path
==
"
/testfolder/subfolder
"
else
:
assert
e
.
role
==
"
File
"
assert
e
.
path
==
"
/testfolder/subfolder/some_data.csv
"
def
test_import_directoy
():
def
test_import_directoy
():
path
=
get_config
().
get
(
"
IntegrationTests
"
,
path
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
...
@@ -797,19 +856,63 @@ def test_import_directoy():
...
@@ -797,19 +856,63 @@ def test_import_directoy():
with
open
(
path
+
"
subfolder/some_data.csv
"
,
"
w
"
)
as
test_file1
:
with
open
(
path
+
"
subfolder/some_data.csv
"
,
"
w
"
)
as
test_file1
:
test_file1
.
write
(
"
hello, world
\n
"
)
test_file1
.
write
(
"
hello, world
\n
"
)
c
=
models
.
Container
()
directory
=
db
.
common
.
models
.
Directory
(
import_file
=
True
,
path
=
"
testfolder/subfolder/
"
)
directory
.
insert
()
re
=
db
.
execute_query
(
"
FIND Entity WHICH IS STORED AT /testfolder/subfolder
"
,
unique
=
True
)
print
(
re
)
assert
re
.
id
==
directory
.
id
assert
re
.
role
==
"
Directory
"
assert
re
.
path
==
"
/testfolder/subfolder
"
finally
:
finally
:
try
:
try
:
c
.
delete
(
)
shutil
.
rmtree
(
path
)
except
BaseException
:
except
BaseException
:
pass
pass
def
test_import_directoy_recursively
():
path
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_import_files_in_dir.local
"
)
+
"
testfolder/
"
try
:
os
.
makedirs
(
path
)
os
.
makedirs
(
path
+
"
subfolder/
"
)
with
open
(
path
+
"
subfolder/some_data.csv
"
,
"
w
"
)
as
test_file1
:
test_file1
.
write
(
"
hello, world
\n
"
)
directory
=
db
.
common
.
models
.
Directory
(
recursive_import
=
True
,
path
=
"
testfolder/subfolder/
"
)
c
=
db
.
Container
()
c
.
append
(
directory
)
c
.
insert
()
assert
len
(
c
)
==
2
for
e
in
c
:
if
e
.
role
==
"
Directory
"
:
assert
e
.
path
==
"
testfolder/subfolder
"
else
:
assert
e
.
role
==
"
File
"
assert
e
.
path
==
"
testfolder/subfolder/some_data.csv
"
re
=
db
.
execute_query
(
"
FIND Entity WHICH IS STORED AT /testfolder/subfolder*
"
)
for
e
in
re
:
if
e
.
role
==
"
Directory
"
:
assert
e
.
path
==
"
testfolder/subfolder
"
else
:
assert
e
.
role
==
"
File
"
assert
e
.
path
==
"
testfolder/subfolder/some_data.csv
"
finally
:
try
:
try
:
shutil
.
rmtree
(
path
)
shutil
.
rmtree
(
path
)
except
BaseException
:
except
BaseException
:
pass
pass
@mark.xfail
(
reason
=
"
Needs file system refactoring
"
)
def
test_consistency_file_was_modified_2
():
def
test_consistency_file_was_modified_2
():
# this test is different from test_consistency_file_was_modified in that
# this test is different from test_consistency_file_was_modified in that
# the server does actually corrupt the file.
# the server does actually corrupt the file.
...
...
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