diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index ecc74fabff91d0c5568a29200f268809ad936518..56c068ebe8e97cf891509448302a4d50eac97c2c 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -17,13 +17,21 @@ services: - type: bind source: ./cert target: /opt/caosdb/cert + - type: volume + source: extroot + target: /opt/caosdb/mnt/extroot + - type: volume + source: scripting + target: /opt/caosdb/git/caosdb-server/scripting/bin ports: # - "from_outside:from_inside" - "10443:10443" - "10080:10080" environment: DEBUG: 1 - +volumes: + scripting: + extroot: networks: caosnet: driver: bridge diff --git a/.docker/pycaosdb.ini b/.docker/pycaosdb.ini index 17b437c3288bd3b10f6b3a1c19c25d7ced27b26f..29846d6f976db29f8bc05d29240a2b4a18fa6ec5 100644 --- a/.docker/pycaosdb.ini +++ b/.docker/pycaosdb.ini @@ -1,8 +1,14 @@ [IntegrationTests] -test_server_side_scripting.bin_dir=../caosdb-server/test_scripting/bin/ +test_server_side_scripting.bin_dir=/scripting-bin/ + +# location of the files from the pyinttest perspective +test_files.test_insert_files_in_dir.local=/extroot/test_insert_files_in_dir/ +# location of the files from the caosdb_servers perspective +test_files.test_insert_files_in_dir.server=/opt/caosdb/mnt/extroot/test_insert_files_in_dir/ + [Connection] -url=https://caosdb-server:10443 +url=https://caosdb-server:10443/ username=admin cacert=/cert/caosdb.cert.pem #cacert=/etc/ssl/cert.pem diff --git a/.docker/tester.yml b/.docker/tester.yml index 634ac13648a516021a98bafe2679347ddf03de6d..c6440787e9ab12f104142c2b0eb577780dd229d0 100644 --- a/.docker/tester.yml +++ b/.docker/tester.yml @@ -8,6 +8,15 @@ services: - type: bind source: ./cert target: /cert + - type: volume + source: extroot + target: /extroot + - type: volume + source: scripting + target: /scripting-bin networks: docker_caosnet: external: true +volumes: + scripting: + extroot: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ec24c323a5b4b14b93b002839bb4ee24aecb22d..65abebef69dd7cf6d46d717e13d098f09a70122b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,16 +60,62 @@ variables: services: - docker:18.09.7-dind -stages: +stages: - setup - cert - style - test + +# During the test stage the CI pipeline (which runs in a "root" docker) starts +# two docker container with docker-compose (one for the caosdb-server, another +# for the mysql-backend). Then a third docker is being started which contains +# the pyintest suite and executes it. +# +# +-------------(root docker)-------------------------+ +# | | +# | +-(caosdb_mysqlbackend)-------------+ | +# | | | | +# | +-----------------------------------+ | +# | +-(caosdb-server)-------------------+ | +# | | | | +# | | /opt/caosdb | | +# | .---->| + /git/caosdb-server/scripting/ | | +# | | .--->| + /mnt/extroot | | +# | | | .->| + /cert | | +# | | | | | | | +# | | | | +-----------------------------------+ | +# | | | | | +# | | | | filesystem: | +# | | | *- /cert -----------. | +# | | | | | +# | | | volumes: | | +# | . *-- extroot ------. | | +# | *---- scripting --. | | | +# | | | | | +# | +-(caosdb-pyinttest)---+ | | | | +# | | | | | | | +# | | /scripting |<---* | | | +# | | /extroot |<----* . | +# | | /cert |<------* | +# | | | | +# | +----------------------+ | +# +---------------------------------------------------+ +# +# In the root docker, the directory /cert is mounted to .docker/cert relative +# to this repository. The directory is created during the cert stage of this +# pipeline and a certificate is created in there. The certificat is then +# available in mounted directories in the server and pyinttest containers. +# +# Two additional volumes in the root docker are shared by the caosdb-server and +# the caosdb-pyintest containers. +# These volumes are inteded to be used for testing server-side scripting and +# file-system features. +# test: tags: [notls] stage: test - image: + image: name: docker/compose:1.24.1 entrypoint: ["/bin/sh", "-c"] script: @@ -80,10 +126,11 @@ test: - docker login -u testuser -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker pull $CI_REGISTRY_IMAGE:latest - cd .docker - - ls + # here the server and the mysql backend docker are being started - CAOSDB_TAG=$CAOSDB_TAG docker-compose up -d - # writes the return value of the tests into the file result - - /bin/sh ./run.sh + # the pyinttest docker writes the return value of the tests into the + # file result + - /bin/sh ./run.sh - docker logs docker_caosdb-server_1 &> ../caosdb_log.txt - docker logs docker_sqldb_1 &> ../mariadb_log.txt - docker-compose down @@ -101,7 +148,7 @@ build-testenv: tags: [notls] image: docker:18.09 stage: setup - script: + script: - docker login -u testuser -p $CI_REGISTRY_PASSWORD $CI_REGISTRY # use here general latest or specific branch latest... - docker pull $CI_REGISTRY_IMAGE:latest || true @@ -129,4 +176,4 @@ style: image: $CI_REGISTRY_IMAGE:latest script: - autopep8 -r --diff --exit-code . - allow_failure: true + allow_failure: true diff --git a/README.md b/README.md index ab14be7b302df6a2291b89270270a6b4517cf0d0..2465f8cb28d99790797511e7527557eb4c8dc2d4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[](https://gitlab.com/caosdb/caosdb-pyinttest/commits/dev) codestyle +[](https://gitlab.com/caosdb/caosdb-pyinttest/commits/dev) # Welcome diff --git a/tests/test_administration.py b/tests/test_administration.py index 6db7c6898739d667601d903564a0d4b4550bcbdb..511e15d38bb5c5945ced658778bfb9790549b2ab 100644 --- a/tests/test_administration.py +++ b/tests/test_administration.py @@ -26,8 +26,7 @@ @author: tf """ -from caosdb import administration as admin -# @UnresolvedImport +from caosdb import (administration as admin, get_config) from nose.tools import assert_true, assert_equal, assert_is_not_none, with_setup, assert_raises from caosdb.exceptions import (ClientErrorException, TransactionError, AuthorizationException, LoginFailedException) diff --git a/tests/test_file.py b/tests/test_file.py index 1dbb3a4fb14a74527f771be466df152b1be63833..3398707728793b993d17af0072bca195ec85ee69 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -41,6 +41,7 @@ from caosdb import execute_query, get_config, get_connection, Info from caosdb.common import models from caosdb.exceptions import EntityError from caosdb.utils.checkFileSystemConsistency import runCheck +from caosdb import administration as admin def setup_module(): @@ -51,8 +52,7 @@ def setup(): upload_file = open("test.dat", "w") upload_file.write("hello world\n") upload_file.close() - os.mkdir("testfolder") - os.mkdir("testfolder/subfolder") + os.makedirs("testfolder/subfolder") with open("testfolder/test1.dat", "w") as upload_file: upload_file.write("hello world\n") with open("testfolder/subfolder/test2.dat", "w") as upload_file: @@ -696,10 +696,3 @@ def test_thumbnails(): # TODO find a better way to check this assert_equal(xml[1][0].get("thumbnail")[-41:], "/Thumbnails/testfiles/thumbnails_test.dat") - - -@with_setup(setup, teardown) -def test_empty_folder(): - """The file system has has problems with empty subfolders.""" - os.mkdir("testfolder/subfolder") - Info() diff --git a/tests/test_query.py b/tests/test_query.py index afbcf4aba778c88009c611acb1b4784a4b34b383..68817f99966c72fb548f3d66e84eb4eadbbc96c8 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -203,8 +203,8 @@ def test_query3(): entity_uri_segments=["Entity"], query_dict={ "query": None}, reconnect=True).read() xml = etree.fromstring(body) - assert xml.xpath("/Response/Query") assert xml.xpath("/Response/TransactionBenchmark") + assert xml.xpath("/Response/Query") assert xml.xpath("/Response/UserInfo") assert_equal(3, len(xml)) @@ -930,8 +930,8 @@ def test_like_query(): def test_backref_like(): h.RecordType("TestData").insert() other = h.Record("other").add_parent("TestData").insert() - sme = h.Record("s_m_e").add_property("TestData", - other.id).add_parent("TestData").insert() + sme = h.Record("s_m_e").add_property( + "TestData", other.id).add_parent("TestData").insert() print(sme) h.execute_query("FIND ENTITY WHICH IS REFERENCED BY s_m_e", unique=True) h.execute_query("FIND ENTITY WHICH IS REFERENCED BY *m*", unique=True) diff --git a/tests/test_server_side_scripting.py b/tests/test_server_side_scripting.py index c4ce22a8d0352aaff2b76f44584abb471c56a105..7a5e595786349c372b72c6e51c47bc31d746ba87 100644 --- a/tests/test_server_side_scripting.py +++ b/tests/test_server_side_scripting.py @@ -31,6 +31,7 @@ from lxml import etree from caosdb import get_connection, get_config from caosdb.exceptions import (EntityDoesNotExistError, ClientErrorException) from caosdb.connection.encode import MultipartParam, multipart_encode +from caosdb import administration as admin _TEST_SCRIPTS = ["not_executable", "ok", "err", "simple_script.py"] _SERVER_SIDE_SCRIPTING_BIN_DIR = get_config().get( @@ -78,6 +79,15 @@ def test_call_script_non_existing(): def test_call_script_not_executable(): + props = admin.get_server_properties() + print(props) + + import os + dirpath = os.getcwd() + print("PWD={}".format(dirpath)) + print("ls ./\n{}".format(os.listdir("./"))) + print("ls ../\n{}".format(os.listdir("../"))) + form = dict() form["call"] = "not_executable" with raises(ClientErrorException) as exc_info: diff --git a/tests/test_webinterface.py b/tests/test_webinterface.py deleted file mode 100644 index b9ba13f083731f3b83a19c3c19fcbb79da84d4bc..0000000000000000000000000000000000000000 --- a/tests/test_webinterface.py +++ /dev/null @@ -1,58 +0,0 @@ -# encoding: utf-8 -# -# ** header v3.0 -# This file is a part of the CaosDB Project. -# -# Copyright (C) 2019 Timm Fitschen (t.fitschen@indiscale.com) -# Copyright (C) 2019 IndiScale GmbH -# Copyright (C) 2019 Daniel Hornung (d.hornung@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/>. -# -# ** end header -# -"""Created on 2019-11-12 - -@author: Timm Fitschen (t.fitschen@indiscale.com) -""" -from urllib import request -from urllib.error import HTTPError -import ssl -import re -import caosdb as c -import pytest - - -def test_webinterface_version_build(): - """Tests if a correct build number is created and returned.""" - url = c.get_config().get("Connection", "url") - - context = ssl.SSLContext() - context.verify_mode = ssl.CERT_NONE - - build_number = request.urlopen(url + "webinterface/version/build", - context=context).read().decode("utf8") - assert re.match(r"\d+", build_number) - - -def test_webinterface(): - """Tests if a 404 error is correctly returned.""" - url = c.get_config().get("Connection", "url") - - context = ssl.SSLContext() - context.verify_mode = ssl.CERT_NONE - - with pytest.raises(HTTPError) as e404: - request.urlopen(url + "webinterface/..", context=context) - assert e404.value.code == 404