Verified Commit 181666d5 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'dev' into f-filesystem

parents 34297ae6 342cdc21
......@@ -28,6 +28,7 @@ stages:
- cert
- style
- test
- deploy
# During the test stage the CI pipeline (which runs in a "root" docker) starts
......@@ -123,6 +124,11 @@ test:
- cd .docker
# here the server and the mysql backend docker are being started
- CAOSDB_TAG=$CAOSDB_TAG docker-compose up -d
# store versions of CaosDB parts
- docker exec -u 0 -t docker_caosdb-server_1 cat /opt/caosdb/git/caosdb_pylib_commit > hash_pylib
- docker exec -u 0 -t docker_caosdb-server_1 cat /opt/caosdb/git/caosdb_webui_commit > hash_webui
- docker exec -u 0 -t docker_caosdb-server_1 cat /opt/caosdb/git/caosdb_server_commit > hash_server
- docker exec -u 0 -t docker_caosdb-server_1 cat /opt/caosdb/git/caosdb_mysqlbackend_commit > hash_mysql
# the pyinttest docker writes the return value of the tests into the
# file result
- /bin/sh ./run.sh
......@@ -138,7 +144,7 @@ test:
paths:
- caosdb_log.txt
- mariadb_log.txt
when: on_failure
- .docker/hash_*
expire_in: 1 week
build-testenv:
......@@ -193,3 +199,25 @@ style:
script:
- autopep8 -r --diff --exit-code .
allow_failure: true
store-version:
tags: [docker]
stage: deploy
dependencies: [test]
image: $CI_REGISTRY_IMAGE
script:
- curl -u gitlab:$REVISONSTOREPW
--data server=$(cat .docker/hash_server)
--data mysql=$(cat .docker/hash_mysql)
--data pylib=$(cat .docker/hash_pylib)
--data webui=$(cat .docker/hash_webui)
--data save=1 https://caosdb.org/revisions/saverev.php
allow_failure: true
only:
- dev
- master
# TODO remove
- f-versions
- web
......@@ -26,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed (for changes in existing functionality)
* Tests comply with the new entity error handling (see
[#32](https://gitlab.com/caosdb/caosdb-pylib/-/issues/32) in
caosdb-pylib).
* `test_recursive_parents.py` now tests inserted entities; set to
xfail until
[caosdb-pylib#34](https://gitlab.com/caosdb/caosdb-pylib/-/issues/34)
......@@ -35,6 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed (for now removed features)
- Some redundant tests from `test_tickets.py` that checked
functionality that was already tested in `test_error_stuff.py`.
### Fixed (for any bug fixes)
* Tests for NaN Double Values (see https://gitlab.com/caosdb/caosdb-server/issues/41)
......
......@@ -27,12 +27,12 @@
"""
from caosdb import administration as admin
from caosdb import get_config
from caosdb.connection.connection import configure_connection, get_connection
from caosdb.exceptions import (AuthorizationException, ClientErrorException,
LoginFailedException, TransactionError)
from caosdb.exceptions import (HTTPClientError, HTTPForbiddenError,
LoginFailedError, HTTPResourceNotFoundError)
from nose.tools import (assert_equal, assert_is_not_none, assert_raises,
assert_true)
from pytest import raises
test_role = "test_role"
test_user = "test_user"
......@@ -104,16 +104,14 @@ def test_insert_role_success():
def test_insert_role_failure_permission():
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._insert_role(name=test_role, description=test_role_desc)
assert_equal(
cm.exception.msg,
"You are not permitted to insert a new role.")
assert cm.value.msg == "You are not permitted to insert a new role."
def test_insert_role_failure_name_duplicates():
test_insert_role_success()
with assert_raises(ClientErrorException) as cm:
with assert_raises(HTTPClientError) as cm:
admin._insert_role(name=test_role, description=test_role_desc)
assert_equal(
cm.exception.msg,
......@@ -132,17 +130,15 @@ def test_update_role_success():
def test_update_role_failure_permissions():
test_insert_role_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._update_role(name=test_role, description=test_role_desc + "asdf")
assert_equal(
cm.exception.msg,
"You are not permitted to update this role.")
assert cm.value.msg == "You are not permitted to update this role."
def test_update_role_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._update_role(name=test_role, description=test_role_desc + "asdf")
assert_equal(cm.exception.msg, "Role does not exist.")
assert cm.value.msg == "Role does not exist."
def test_delete_role_success():
......@@ -153,17 +149,15 @@ def test_delete_role_success():
def test_delete_role_failure_permissions():
test_insert_role_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._delete_role(name=test_role)
assert_equal(
cm.exception.msg,
"You are not permitted to delete this role.")
assert cm.value.msg == "You are not permitted to delete this role."
def test_delete_role_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._delete_role(name=test_role)
assert_equal(cm.exception.msg, "Role does not exist.")
assert cm.value.msg == "Role does not exist."
def test_retrieve_role_success():
......@@ -175,17 +169,15 @@ def test_retrieve_role_success():
def test_retrieve_role_failure_permission():
test_insert_role_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._retrieve_role(name=test_role)
assert_equal(
cm.exception.msg,
"You are not permitted to retrieve this role.")
assert cm.value.msg == "You are not permitted to retrieve this role."
def test_retrieve_role_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._retrieve_role(name=test_role)
assert_equal(cm.exception.msg, "Role does not exist.")
assert cm.value.msg == "Role does not exist."
def test_set_permissions_success():
......@@ -202,23 +194,21 @@ def test_set_permissions_success():
def test_set_permissions_failure_permissions():
test_insert_role_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._set_permissions(
role=test_role, permission_rules=[
admin.PermissionRule(
"Grant", "BLA:BLA:BLA")])
assert_equal(
cm.exception.msg,
"You are not permitted to set this role's permissions.")
assert cm.value.msg == "You are not permitted to set this role's permissions."
def test_set_permissions_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._set_permissions(
role=test_role, permission_rules=[
admin.PermissionRule(
"Grant", "BLA:BLA:BLA")])
assert_equal(cm.exception.msg, "Role does not exist.")
assert cm.value.msg == "Role does not exist."
def test_get_permissions_success():
......@@ -231,17 +221,15 @@ def test_get_permissions_success():
def test_get_permissions_failure_permissions():
test_set_permissions_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._get_permissions(role=test_role)
assert_equal(
cm.exception.msg,
"You are not permitted to retrieve this role's permissions.")
assert cm.value.msg == "You are not permitted to retrieve this role's permissions."
def test_get_permissions_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._get_permissions(role="non-existing-role")
assert_equal(cm.exception.msg, "Role does not exist.")
assert cm.value.msg == "Role does not exist."
def test_get_roles_success():
......@@ -255,17 +243,15 @@ def test_get_roles_success():
def test_get_roles_failure_permissions():
test_insert_role_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._get_roles(username=test_user)
assert_equal(
cm.exception.msg,
"You are not permitted to retrieve this user's roles.")
assert cm.value.msg == "You are not permitted to retrieve this user's roles."
def test_get_roles_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._get_roles(username="non-existing-user")
assert_equal(cm.exception.msg, "User does not exist.")
assert cm.value.msg == "User does not exist."
def test_set_roles_success():
......@@ -290,16 +276,14 @@ def test_set_roles_failure_permissions():
roles = {test_role}
roles.union(roles_old)
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._set_roles(username=test_user, roles=roles_old)
assert_equal(
cm.exception.msg,
"You are not permitted to set this user's roles.")
assert cm.value.msg == "You are not permitted to set this user's roles."
def test_set_roles_failure_non_existing_role():
roles = {"non-existing-role"}
with assert_raises(ClientErrorException) as cm:
with assert_raises(HTTPClientError) as cm:
admin._set_roles(username=test_user, roles=roles)
assert_equal(cm.exception.msg, "Role does not exist.")
......@@ -307,9 +291,9 @@ def test_set_roles_failure_non_existing_role():
def test_set_roles_failure_non_existing_user():
test_insert_role_success()
roles = {test_role}
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._set_roles(username="non-existing-user", roles=roles)
assert_equal(cm.exception.msg, "User does not exist.")
assert cm.value.msg == "User does not exist."
def test_insert_user_success():
......@@ -323,21 +307,19 @@ def test_insert_user_success():
def test_insert_user_failure_permissions():
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._insert_user(
name=test_user,
password="secret1P!",
status="ACTIVE",
email="email@example.com",
entity=None)
assert_equal(
cm.exception.msg,
"You are not permitted to insert a new user.")
assert cm.value.msg == "You are not permitted to insert a new user."
def test_insert_user_failure_name_in_use():
test_insert_user_success()
with assert_raises(ClientErrorException) as cm:
with assert_raises(HTTPClientError) as cm:
test_insert_user_success()
assert_equal(cm.exception.msg, "User name is already in use.")
......@@ -350,17 +332,15 @@ def test_delete_user_success():
def test_delete_user_failure_permissions():
test_insert_user_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._delete_user(name="non_existing_user")
assert_equal(
cm.exception.msg,
"You are not permitted to delete this user.")
assert cm.value.msg == "You are not permitted to delete this user."
def test_delete_user_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._delete_user(name="non_existing_user")
assert_equal(cm.exception.msg, "User does not exist.")
assert cm.value.msg == "User does not exist."
def test_update_user_success_status():
......@@ -427,15 +407,12 @@ def test_update_user_success_password():
def test_update_user_failure_permissions_status():
assert_is_not_none(
admin._insert_user(
name=test_user + "2",
password="secret1P!",
status="INACTIVE",
email="email@example.com",
entity=None))
assert admin._insert_user(name=test_user + "2",
password="secret1P!",
status="INACTIVE",
email="email@example.com", entity=None) is not None
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._update_user(
realm=None,
name=test_user + "2",
......@@ -443,21 +420,15 @@ def test_update_user_failure_permissions_status():
status="ACTIVE",
email=None,
entity=None)
assert_equal(
cm.exception.msg,
"You are not permitted to update this user.")
assert cm.value.msg == "You are not permitted to update this user."
def test_update_user_failure_permissions_email():
assert_is_not_none(
admin._insert_user(
name=test_user + "2",
password="secret1P!",
status="ACTIVE",
email="email@example.com",
entity=None))
assert admin._insert_user(name=test_user + "2",
password="secret1P!", status="ACTIVE",
email="email@example.com", entity=None) is not None
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._update_user(
realm=None,
name=test_user + "2",
......@@ -465,21 +436,15 @@ def test_update_user_failure_permissions_email():
status=None,
email="newemail@example.com",
entity=None)
assert_equal(
cm.exception.msg,
"You are not permitted to update this user.")
assert cm.value.msg == "You are not permitted to update this user."
def test_update_user_failure_permissions_entity():
assert_is_not_none(
admin._insert_user(
name=test_user + "2",
password="secret1P!",
status="ACTIVE",
email="email@example.com",
entity=None))
assert admin._insert_user(name=test_user + "2",
password="secret1P!", status="ACTIVE",
email="email@example.com", entity=None) is not None
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._update_user(
realm=None,
name=test_user + "2",
......@@ -487,21 +452,15 @@ def test_update_user_failure_permissions_entity():
status=None,
email=None,
entity=21)
assert_equal(
cm.exception.msg,
"You are not permitted to update this user.")
assert cm.value.msg == "You are not permitted to update this user."
def test_update_user_failure_permissions_password():
assert_is_not_none(
admin._insert_user(
name=test_user + "2",
password="secret1P!",
status="ACTIVE",
email="email@example.com",
entity=None))
assert admin._insert_user(name=test_user + "2",
password="secret1P!", status="ACTIVE",
email="email@example.com", entity=None) is not None
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._update_user(
realm=None,
name=test_user + "2",
......@@ -509,13 +468,11 @@ def test_update_user_failure_permissions_password():
status=None,
email=None,
entity=None)
assert_equal(
cm.exception.msg,
"You are not permitted to update this user.")
assert cm.value.msg == "You are not permitted to update this user."
def test_update_user_failure_non_existing_user():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._update_user(
realm=None,
name="non-existing-user",
......@@ -523,18 +480,14 @@ def test_update_user_failure_non_existing_user():
status="ACTIVE",
email="email@example.com",
entity=None)
assert_equal(cm.exception.msg, "User does not exist.")
assert cm.value.msg == "User does not exist."
def test_update_user_failure_non_existing_entity():
assert_is_not_none(
admin._insert_user(
name=test_user + "2",
password="secret1P!",
status="ACTIVE",
email="email@example.com",
entity=None))
with assert_raises(ClientErrorException) as cm:
assert admin._insert_user(name=test_user + "2",
password="secret1P!", status="ACTIVE",
email="email@example.com", entity=None) is not None
with raises(HTTPClientError) as cm:
admin._update_user(
realm=None,
name=test_user + "2",
......@@ -542,7 +495,7 @@ def test_update_user_failure_non_existing_entity():
status=None,
email=None,
entity=100000)
assert_equal(cm.exception.msg, "Entity does not exist.")
assert cm.value.msg == "Entity does not exist."
def test_retrieve_user_success():
......@@ -553,17 +506,15 @@ def test_retrieve_user_success():
def test_retrieve_user_failure_permissions():
test_insert_user_success()
switch_to_normal_user()
with assert_raises(AuthorizationException) as cm:
with raises(HTTPForbiddenError) as cm:
admin._retrieve_user(realm=None, name=test_user + "2")
assert_equal(
cm.exception.msg,
"You are not permitted to retrieve this user.")
assert cm.value.msg == "You are not permitted to retrieve this user."
def test_retrieve_user_failure_non_existing():
with assert_raises(TransactionError) as cm:
with raises(HTTPResourceNotFoundError) as cm:
admin._retrieve_user(realm=None, name="non_existing")
assert_equal(cm.exception.msg, "User does not exist.")
assert cm.value.msg == "User does not exist."
def test_login_with_inactive_user_failure():
......@@ -576,5 +527,5 @@ def test_login_with_inactive_user_failure():
entity=None))
configure_connection(username=test_user + "2", password="secret1P!",
password_method="plain")
with assert_raises(LoginFailedException):
with assert_raises(LoginFailedError):
get_connection()._login()
......@@ -25,9 +25,10 @@
@author: tf
"""
import caosdb as db
import os
from nose.tools import nottest, assert_true, assert_raises, assert_equal, with_setup, assert_is_not_none # @UnresolvedImport
import caosdb as db
from nose.tools import nottest, assert_true, assert_equal, with_setup, assert_is_not_none
from pytest import raises
def setup_module():
......@@ -85,31 +86,33 @@ def test_rec_rt_is_instantiation():
@with_setup(setup, teardown)
def test_rec_prop_is_invalid():
with assert_raises(db.EntityError) as cm:
with raises(db.TransactionError) as cm:
db.Record(name="TestRecordChild").add_parent(name=prop_name).insert()
assert_equal(
cm.exception.get_errors()[0].msg,
"Affiliation is not defined for this child-parent constellation.")
assert cm.value.has_error(db.UnqualifiedParentsError)
# TransactionError with UnqualifiedParentsError with EntityError
# caused by wrong affiliation
ee = cm.value.errors[0].errors[0]
assert ee.msg == "Affiliation is not defined for this child-parent constellation."
@with_setup(setup, teardown)
def test_rec_file_is_invalid():
with assert_raises(db.EntityError) as cm:
with raises(db.TransactionError) as cm:
db.Record(name="TestRecordChild").add_parent(name=file_name).insert()
assert_equal(
cm.exception.get_errors()[0].msg,
"Affiliation is not defined for this child-parent constellation.")
assert cm.value.has_error(db.UnqualifiedParentsError)
ee = cm.value.errors[0].errors[0]
assert ee.msg == "Affiliation is not defined for this child-parent constellation."
@with_setup(setup, teardown)
def test_rt_rec_is_invalid():
with assert_raises(db.EntityError) as cm:
with raises(db.TransactionError) as cm:
db.RecordType(
name="TestRecordTypeChild").add_parent(
name=rec_name).insert()
assert_equal(
cm.exception.get_errors()[0].msg,
"Affiliation is not defined for this child-parent constellation.")
assert cm.value.has_error(db.UnqualifiedParentsError)
ee = cm.value.errors[0].errors[0]
assert ee.msg == "Affiliation is not defined for this child-parent constellation."
@with_setup(setup, teardown)
......@@ -121,48 +124,48 @@ def test_rt_rt_is_subtyping():
@with_setup(setup, teardown)
def test_rt_prop_is_invalid():
with assert_raises(db.EntityError) as cm:
with raises(db.TransactionError) as cm:
db.RecordType(
name="TestRecordTypeChild").add_parent(
name=prop_name).insert()
assert_equal(
cm.exception.get_errors()[0].msg,
"Affiliation is not defined for this child-parent constellation.")
assert cm.value.has_error(db.UnqualifiedParentsError)
ee = cm.value.errors[0].errors[0]
assert ee.msg == "Affiliation is not defined for this child-parent constellation."
@with_setup(setup, teardown)
def test_rt_file_is_invalid():
with assert_raises(db.EntityError) as cm:
with raises(db.TransactionError) as cm:
db.RecordType(
name="TestRecordTypeChild").add_parent(
name=file_name).insert()
assert_equal(
cm.exception.get_errors()[0].msg,
"Affiliation is not defined for this child-parent constellation.")
assert cm.value.has_error(db.UnqualifiedParentsError)
ee = cm.value.errors[0].errors[0]
assert ee.msg == "Affiliation is not defined for this child-parent constellation."
@with_setup(setup, teardown)
def test_prop_rec_is_invalid():
with assert_raises(db.EntityError) as cm:
with raises(db.TransactionError) as cm:
db.Property(
name="TestPropertyChild",
datatype=db.TEXT).add_parent(
name=rec_name).insert()
assert_equal(
cm.exception.get_errors()[0].msg,
"Affiliation is not defined for this child-parent constellation.")
assert cm.value.has_error(db.UnqualifiedParentsError)
ee = cm.value.errors[0].errors[0]
assert ee.msg == "Affiliation is not defined for this child-parent constellation."