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

Merge branch 'dev' into f-server-154

parents 4730a6d0 2740a3c7
No related branches found
No related tags found
1 merge request!13Tests for caosdb-server#154
Pipeline #12908 failed
......@@ -4,7 +4,7 @@ RUN apt-get update && \
curl \
git \
openjdk-11-jdk-headless \
python-autopep8 \
python3-autopep8 \
python3-pip \
tox \
-y
......
......@@ -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
# encoding: utf-8
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from pytest import raises, mark
import caosdb as db
def setup():
teardown()
def teardown():
d = db.execute_query("FIND Test*")
if len(d) > 0:
d.delete()
@mark.xfail(reason="Should raise an error or at least a warning. "
"caosdb-server#171")
def test_parent_name_id_mismatch():
rt1 = db.RecordType(name="TestRT1").insert()
rt2 = db.RecordType(name="TestRT2").add_parent(id=rt1.id, name=rt1.name +
"_wrong")
with raises(db.TransactionError):
rt2.insert()
print(rt2)
......@@ -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()
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment