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
5ddc285b
Verified
Commit
5ddc285b
authored
Jan 10, 2020
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
TST: fix
parent
8c90d14a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_file.py
+93
-103
93 additions, 103 deletions
tests/test_file.py
tests/test_misc.py
+1
-1
1 addition, 1 deletion
tests/test_misc.py
tox.ini
+1
-1
1 addition, 1 deletion
tox.ini
with
95 additions
and
105 deletions
tests/test_file.py
+
93
−
103
View file @
5ddc285b
...
...
@@ -33,6 +33,7 @@ from random import randint
from
sys
import
maxsize
as
maxint
from
lxml
import
etree
from
pytest
import
raises
from
nose.tools
import
(
assert_equal
,
assert_false
,
# @UnresolvedImport
assert_is_not_none
,
assert_raises
,
assert_true
,
nottest
,
with_setup
)
...
...
@@ -231,8 +232,8 @@ def test_file6():
file
=
"
test.dat
"
)
file_
.
insert
()
assert
_
is
_
not
_n
one
(
file_
.
id
)
assert
_true
(
file_
.
is_valid
()
)
assert
file_
.
id
is
not
N
one
assert
file_
.
is_valid
()
# pickup_folder
# and try to store it to testfiles2/
...
...
@@ -256,9 +257,12 @@ def test_file6():
name
=
"
PickupTestfolder
"
,
description
=
"
Pickup test folder desc
"
,
path
=
"
testfiles2/
"
,
pickup
=
"
path
"
)
pickup
=
path
)
assert_raises
(
EntityError
,
folder_
.
insert
)
with
raises
(
EntityError
)
as
cm
:
folder_
.
insert
()
errors
=
cm
.
value
.
entity
.
get_errors
()
assert
errors
[
0
].
description
==
'
This target path does already exist.
'
finally
:
try
:
folder_
.
delete
()
...
...
@@ -345,39 +349,35 @@ def test_consistency_file_was_modified():
file
=
"
test.dat
"
)
file_
.
insert
()
assert
_
is
_
not
_n
one
(
file_
.
id
)
assert
_true
(
file_
.
is_valid
()
)
assert
file_
.
id
is
not
N
one
assert
file_
.
is_valid
()
# run consistency check (no consistency warning)
c
=
runCheck
(
None
,
None
)
assert
_is_not_none
(
c
.
messages
[
"
Info
"
,
0
]
)
assert
_equal
(
c
.
messages
[
"
Info
"
,
0
][
0
]
,
"
File system is consistent.
"
)
assert
c
.
messages
[
"
Info
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Info
"
,
0
][
0
]
==
"
File system is consistent.
"
# run consistency check with modified warning)
# TODO fix
# This smells badly. The argument is meant to transport the location
# that is checked. Understanding of the code is difficult.
# when in debug mode, the server offers a special option
#
# TODO reactivate if meaningful
# Why is it expeced that the file was modified?
#c = runCheck(None, "-c FILE_WAS_MODIFIED")
# print(c.messages)
#assert_is_not_none(c.messages["Error", 0])
# assert_equal(
#c.messages["Error", 0][0],
# 'debug/test_file_storage_consistency: File was modified.')
# '-c FILE_WAS_MODIFIED'
#
# which simulates a modified file.
c
=
runCheck
(
None
,
"
-c FILE_WAS_MODIFIED
"
)
assert
c
.
messages
[
"
Error
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Error
"
,
0
][
0
]
==
'
debug/test_file_storage_consistency: File was modified.
'
# download file again and check if it is still the same (just to be
# sure that the server only simulated the consistency breach
d
=
open
(
file_
.
download
(
target
=
"
test.dat.tmp
"
),
"
r
"
)
r
=
d
.
read
()
assert
_equal
(
r
,
"
hello world
\n
"
)
assert
r
==
"
hello world
\n
"
# run a passing check again
c
=
runCheck
(
None
,
None
)
assert
_is_not_none
(
c
.
messages
[
"
Info
"
,
0
]
)
assert
_equal
(
c
.
messages
[
"
Info
"
,
0
][
0
]
,
"
File system is consistent.
"
)
assert
c
.
messages
[
"
Info
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Info
"
,
0
][
0
]
==
"
File system is consistent.
"
finally
:
# clean up file record
...
...
@@ -411,34 +411,29 @@ def test_consistency_file_does_not_exist():
file
=
"
test.dat
"
)
file_
.
insert
()
assert
_
is
_
not
_n
one
(
file_
.
id
)
assert
_true
(
file_
.
is_valid
()
)
assert
file_
.
id
is
not
N
one
assert
file_
.
is_valid
()
c
=
runCheck
(
None
,
"
/debug/
"
)
assert_is_not_none
(
c
.
messages
[
"
Info
"
,
0
])
assert_equal
(
c
.
messages
[
"
Info
"
,
0
][
0
],
"
File system below debug/ is consistent.
"
)
assert
c
.
messages
[
"
Info
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Info
"
,
0
][
0
]
==
"
File system below debug/ is consistent.
"
# TODO fix
# This smells badly. The argument is meant to transport the location
# that is checked. Understanding of the code is difficult.
# when in debug mode, the server offers a special option
#
# TODO reactivate if meaningful
# Furthermore, I have no clue, why the file that was just successfully
# inserted should lead to a FILE_DOES_NOT_EXIST error.
#c = runCheck(None, "-c FILE_DOES_NOT_EXIST")
#assert_is_not_none(c.messages["Error", 0])
# assert_equal(
# c.messages["Error", 0][0],
# 'debug/test_file_storage_consistency: File does not exist.')
# '-c FILE_DOES_NOT_EXIST'
#
# which simulates a accidentially removed file.
c
=
runCheck
(
None
,
"
-c FILE_DOES_NOT_EXIST
"
)
assert
c
.
messages
[
"
Error
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Error
"
,
0
][
0
]
==
'
debug/test_file_storage_consistency: File does not exist.
'
with
open
(
file_
.
download
(
target
=
"
test.dat.tmp
"
),
"
r
"
)
as
d
:
r
=
d
.
read
()
assert
_equal
(
r
,
"
hello world
\n
"
)
assert
r
==
"
hello world
\n
"
c
=
runCheck
(
None
,
None
)
assert
_is_not_none
(
c
.
messages
[
"
Info
"
,
0
]
)
assert
_equal
(
c
.
messages
[
"
Info
"
,
0
][
0
]
,
"
File system is consistent.
"
)
assert
c
.
messages
[
"
Info
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Info
"
,
0
][
0
]
==
"
File system is consistent.
"
finally
:
try
:
...
...
@@ -462,23 +457,21 @@ def test_consistency_file_does_not_exist():
@with_setup
(
setup
,
teardown
)
def
test_consistency_unknown_file
():
c
=
runCheck
(
None
,
None
)
assert
_is_not_none
(
c
.
messages
[
"
Info
"
,
0
]
)
assert
_equal
(
c
.
messages
[
"
Info
"
,
0
][
0
]
,
"
File system is consistent.
"
)
assert
c
.
messages
[
"
Info
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Info
"
,
0
][
0
]
==
"
File system is consistent.
"
#
TODO fix
#
This smells badly. The argument is meant to transport the location
#
that is checked. Understanding of the code is difficult.
#
when in debug mode, the server offers a special option
#
#
'-c UNKNOWN_FILE'
#
# TODO reactivate if meaningful
# It is unclear what this is supposed to test. How should a file be created
# under debug. Does not look meaningful.
#c = runCheck(None, "-c UNKNOWN_FILE")
#assert_is_not_none(c.messages["Warning", 0])
#assert_equal(c.messages["Warning", 0][0], 'debug/: Unknown file.')
# which simulates an unknown file.
c
=
runCheck
(
None
,
"
-c UNKNOWN_FILE
"
)
assert
c
.
messages
[
"
Warning
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Warning
"
,
0
][
0
]
==
'
debug/: Unknown file.
'
#
c = runCheck(None, None)
#
assert
_is_not_none(
c.messages["Info", 0]
)
#
assert
_equal(
c.messages["Info", 0][0]
,
"File system is consistent."
)
c
=
runCheck
(
None
,
None
)
assert
c
.
messages
[
"
Info
"
,
0
]
is
not
None
assert
c
.
messages
[
"
Info
"
,
0
][
0
]
==
"
File system is consistent.
"
@with_setup
(
setup
,
teardown
)
...
...
@@ -693,48 +686,48 @@ def test_insert_files_in_dir():
except
BaseException
:
pass
# TODO reactivate
# No files are insered currently eventhough the other InserFilesInDir tests
# work. What is the current behaviour of the
regex
p?
# @with_setup(setup, teardown)
# def test_insert_files_in_dir_regex():
#
# TODO
# path = get_config().get("IntegrationTests",
# "test_files.test_insert_files_in_dir.local") + "testfolder/"
#
path_on_server = get_config().get("IntegrationTests",
# "test_files.test_insert_files_in_dir.server") + "test
folder/"
#
t
ry:
#
os.makedirs(path
)
#
os.makedirs(path + "subfolder/"
)
# test_file1 = open(path + "subfolder/test.dat", "w")
#
test_file
1.write("hello world\n
")
#
test_file
1.close(
)
#
# test_file2 = open(path + "subfolder/test2.dat", "w")
#
test_file2.write("hello world2\n"
)
#
test_file2.clos
e(
)
#
#
c = models.Container()
#
c.retrieve(
#
unique=False,
#
raise_exception
_on_er
ror=False,
#
flags={
#
"InsertFilesInDir": "-e test " +
#
path_on_server
}
)
# assert c.messages["Warning", 2] is not None
#
assert c.messages["Warning", 2][0] == "Explicitly excluded directory or file: {}".format(
#
path_on_server[:-1])
#
assert
len(c) == 0
#
#
finally:
#
try:
#
c.delete()
#
except BaseException:
#
pass
#
try:
#
shutil.rmtree(path)
#
except BaseException:
#
pass
@with_setup
(
setup
,
teardown
)
def
test_insert_files_in_dir_
regex
():
path
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_insert_files_in_dir.local
"
)
+
"
testfolder/
"
path_on_server
=
get_config
().
get
(
"
IntegrationTests
"
,
"
test_files.test_insert_files_in_dir.server
"
)
+
"
testfolder/
"
try
:
os
.
makedirs
(
path
)
os
.
makedirs
(
path
+
"
sub
folder/
"
)
t
est_file1
=
open
(
path
+
"
subfolder/test_dont_insert.dat
"
,
"
w
"
)
test_file1
.
write
(
"
hello world
\n
"
)
test_file1
.
close
(
)
test_file
2
=
open
(
path
+
"
subfolder/test_insert.dat
"
,
"
w
"
)
test_file
2
.
write
(
"
hello world2
\n
"
)
test_file2
.
close
()
c
=
models
.
Container
(
)
c
.
retriev
e
(
unique
=
False
,
raise_exception_on_error
=
False
,
flags
=
{
"
InsertFilesInDir
"
:
"
-e dont_insert
"
+
path
_on_
s
er
ver
})
assert
c
.
messages
[
"
Warning
"
,
2
]
is
not
None
assert
c
.
messages
[
"
Warning
"
,
2
][
0
]
==
"
Explicitly excluded file: {}
"
.
format
(
path_on_server
+
"
subfolder/test_dont_insert.dat
"
)
# the other has been inserted
assert
len
(
c
)
==
1
assert
c
[
0
].
name
==
"
test_insert.dat
"
finally
:
try
:
c
.
delete
()
except
BaseException
:
pass
try
:
shutil
.
rmtree
(
path
)
except
BaseException
:
pass
@with_setup
(
setup
,
teardown
)
...
...
@@ -752,8 +745,5 @@ def test_thumbnails():
reconnect
=
True
).
read
()
print
(
body
)
xml
=
etree
.
fromstring
(
body
)
assert
xml
.
xpath
(
'
/Response
'
)
assert
xml
.
xpath
(
'
/Response/dir/file
'
)
# TODO find a better way to check this
assert_equal
(
xml
[
1
][
0
].
get
(
"
thumbnail
"
)[
-
41
:],
"
/Thumbnails/testfiles/thumbnails_test.dat
"
)
assert
xml
.
xpath
(
'
/Response/dir/file
'
)[
0
].
get
(
"
thumbnail
"
)[
-
41
:]
==
"
/Thumbnails/testfiles/thumbnails_test.dat
"
This diff is collapsed.
Click to expand it.
tests/test_misc.py
+
1
−
1
View file @
5ddc285b
...
...
@@ -61,7 +61,7 @@ def test_file_system_returns_ids():
body
=
resp
.
read
()
print
(
body
)
print
(
type
(
body
))
search
=
"
<file
id=
\"
"
+
str
(
file_
.
id
)
+
"
\"
name=
\"
test.dat
\"
"
search
=
"
id=
\"
"
+
str
(
file_
.
id
)
+
"
\"
"
print
(
search
)
assert_true
(
search
in
str
(
body
))
...
...
This diff is collapsed.
Click to expand it.
tox.ini
+
1
−
1
View file @
5ddc285b
[tox]
envlist
=
py37
envlist
=
py36
py37
py38
skip_missing_interpreters
=
true
[testenv]
setenv
=
PASSWORD_STORE_DIR = {env:HOME}/.password-store
...
...
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