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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Python Integration Tests
Commits
06205692
Verified
Commit
06205692
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev' of gitlab.indiscale.com:caosdb/src/caosdb-pyinttest into dev
parents
bc92027e
435bc66d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#12899
failed
3 years ago
Stage: cert
Stage: style
Stage: test
Stage: deploy
Changes
2
Pipelines
8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_misc.py
+10
-0
10 additions, 0 deletions
tests/test_misc.py
tests/test_server_side_scripting.py
+23
-10
23 additions, 10 deletions
tests/test_server_side_scripting.py
with
33 additions
and
10 deletions
tests/test_misc.py
+
10
−
0
View file @
06205692
...
...
@@ -34,6 +34,7 @@ import caosdb as db
from
caosdb
import
(
Container
,
Info
,
Property
,
Record
,
RecordType
,
execute_query
)
from
pytest
import
raises
from
pytest
import
mark
def
setup
():
...
...
@@ -581,3 +582,12 @@ def test_cache_performance():
t2
=
t
.
time
()
-
t1
print
(
"
Time [s]:
"
+
str
(
t2
))
n
+=
10
@mark.xfail
(
reason
=
"
Waits for MR https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/merge_requests/15
"
)
def
test_role_after_retrieve
():
rt
=
db
.
RecordType
(
"
TestRT
"
).
insert
()
entity
=
db
.
Entity
(
id
=
rt
.
id
)
assert
entity
.
role
is
None
entity
.
retrieve
()
assert
entity
.
role
==
rt
.
role
This diff is collapsed.
Click to expand it.
tests/test_server_side_scripting.py
+
23
−
10
View file @
06205692
...
...
@@ -26,20 +26,22 @@
Integration tests for the implementation of the server-side-scripting api.
"""
from
__future__
import
print_function
,
unicode_literals
import
json
import
os
import
ssl
import
tempfile
from
pytest
import
raises
,
mark
import
json
from
lxml
import
etree
from
http.client
import
HTTPSConnection
import
ssl
from
caosdb
import
get_connection
,
get_config
,
Info
,
execute_query
,
RecordType
from
caosdb
.exceptions
import
(
HTTPClientError
,
HTTPResourceNotFoundError
)
from
caosdb
import
Info
,
RecordType
from
caosdb
import
administration
as
admin
from
caosdb
import
execute_query
,
get_config
,
get_connection
from
caosdb.connection.encode
import
MultipartParam
,
multipart_encode
from
caosdb.connection.utils
import
urlencode
,
urlparse
from
caosdb
import
administration
as
admin
from
caosdb
.exceptions
import
HTTPClientError
,
HTTPResourceNotFoundError
from
caosdb.utils.server_side_scripting
import
run_server_side_script
from
lxml
import
etree
from
pytest
import
mark
,
raises
_TEST_SCRIPTS
=
[
"
not_executable
"
,
"
ok
"
,
"
err
"
,
"
ok_anonymous
"
]
...
...
@@ -63,6 +65,7 @@ _ORIGINAL_SERVER_SCRIPTING_BIN_DIR = ""
def
clean_database
():
admin
.
_set_permissions
(
"
anonymous
"
,
[])
d
=
execute_query
(
"
FIND ENTITY WITH ID > 99
"
)
if
len
(
d
)
>
0
:
d
.
delete
()
...
...
@@ -84,15 +87,17 @@ def setup_module():
clean_database
()
from
os
import
makedirs
from
os.path
import
join
,
isdir
,
exists
from
os.path
import
exists
,
isdir
,
join
from
shutil
import
copyfile
,
copymode
print
(
"
bin dir (local):
"
+
str
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
))
print
(
"
bin dir (server):
"
+
str
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_SERVER
))
print
(
"
tests scripts:
"
+
str
(
_TEST_SCRIPTS
))
if
not
exists
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
):
makedirs
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
)
_REMOVE_FILES_AFTERWARDS
.
append
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
)
assert
isdir
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
)
for
script_file
in
_TEST_SCRIPTS
:
target
=
join
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
,
script_file
)
src
=
join
(
_TEST_SCRIPTS_DIR
,
script_file
)
...
...
@@ -105,6 +110,7 @@ def teardown_module():
from
os
import
remove
from
os.path
import
exists
,
isdir
from
shutil
import
rmtree
for
obsolete
in
_REMOVE_FILES_AFTERWARDS
:
if
exists
(
obsolete
):
if
isdir
(
obsolete
):
...
...
@@ -160,6 +166,7 @@ def test_call_err():
assert
xml
.
xpath
(
"
/Response/script/stderr
"
)[
0
].
text
==
"
err
"
@mark.xfail
(
reason
=
(
"
package incompatibility: pandas and numexpr
"
))
def
test_run_server_side_script_with_file_as_positional_param
():
RecordType
(
"
TestRT
"
).
insert
()
_REMOVE_FILES_AFTERWARDS
.
append
(
"
test_file.txt
"
)
...
...
@@ -185,6 +192,7 @@ def test_run_server_side_script_with_file_as_positional_param():
assert
"
./.upload_files/test_file.txt
"
in
json_data
[
"
files
"
]
@mark.xfail
(
reason
=
(
"
package incompatibility: pandas and numexpr
"
))
def
test_run_server_side_script_with_additional_file
():
RecordType
(
"
TestRT
"
).
insert
()
_REMOVE_FILES_AFTERWARDS
.
append
(
"
test_file.txt
"
)
...
...
@@ -208,6 +216,7 @@ def test_run_server_side_script_with_additional_file():
assert
"
./.upload_files/test_file.txt
"
in
json_data
[
"
files
"
]
@mark.xfail
(
reason
=
(
"
package incompatibility: pandas and numexpr
"
))
def
test_diagnostics_basic
():
RecordType
(
"
TestRT
"
).
insert
()
...
...
@@ -246,6 +255,7 @@ def test_diagnostics_basic():
assert
xml
.
xpath
(
"
/Response/script/stderr
"
)[
0
].
text
is
None
@mark.xfail
(
reason
=
(
"
package incompatibility: pandas and numexpr
"
))
def
test_diagnostics_with_file_upload
():
RecordType
(
"
TestRT
"
).
insert
()
_REMOVE_FILES_AFTERWARDS
.
append
(
"
test_file.txt
"
)
...
...
@@ -330,6 +340,7 @@ def request(method, headers, path, body=None):
"""
context
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_TLSv1_2
)
context
.
verify_mode
=
ssl
.
CERT_REQUIRED
if
hasattr
(
context
,
"
check_hostname
"
):
context
.
check_hostname
=
True
context
.
load_verify_locations
(
get_config
().
get
(
"
Connection
"
,
"
cacert
"
))
...
...
@@ -341,6 +352,7 @@ def request(method, headers, path, body=None):
str
(
fullurl
.
netloc
),
timeout
=
200
,
context
=
context
)
http_con
.
request
(
method
=
method
,
headers
=
headers
,
url
=
str
(
fullurl
.
path
)
+
path
,
body
=
body
)
return
http_con
.
getresponse
()
...
...
@@ -364,7 +376,7 @@ def test_anonymous_script_calling_not_permitted():
assert
response
.
getheader
(
"
Set-Cookie
"
)
is
None
# no auth token returned
@mark.local_server
@
mark
.
local_server
def
test_anonymous_script_calling_success
():
admin
.
set_server_property
(
"
SERVER_SIDE_SCRIPTING_BIN_DIRS
"
,
_SERVER_SIDE_SCRIPTING_BIN_DIR_SERVER
)
...
...
@@ -398,6 +410,7 @@ def test_anonymous_script_calling_success():
@mark.local_server
def
test_evil_path
():
subdir
=
os
.
path
.
join
(
_SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL
,
"
subdir
"
)
if
not
os
.
path
.
exists
(
subdir
):
os
.
makedirs
(
subdir
)
_REMOVE_FILES_AFTERWARDS
.
append
(
subdir
)
...
...
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