Skip to content
Snippets Groups Projects
Commit 661f2c5a authored by florian's avatar florian
Browse files

WIP: Update test_error_stuff.py

parent 7059554d
Branches
Tags
No related merge requests found
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2020 Florian Spreckelsen <f.spreckelsen@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -21,62 +23,67 @@ ...@@ -21,62 +23,67 @@
# #
# ** end header # ** end header
# #
"""Created on 19.02.2015. """Test different entity errors.
Created on 19.02.2015.
@author: tf @author: tf
""" """
from caosdb.exceptions import EntityDoesNotExistError, UniqueNamesError,\ import caosdb as h
TransactionError, EntityError, UnqualifiedPropertiesError,\ from caosdb.exceptions import (EntityDoesNotExistError,
EntityHasNoDatatypeError, UnqualifiedParentsError UniqueNamesError, TransactionError, EntityError,
UnqualifiedPropertiesError, EntityHasNoDatatypeError,
UnqualifiedParentsError)
import pytest
def test_retrieval_no_exception_raised(): def setup_module():
import caosdb as h try:
from nose.tools import assert_true, assert_false # @UnresolvedImport h.execute_query("FIND Test*").delete()
except:
pass
p = h.Property(name="Non-ExsistentProperty").retrieve(unique=True,
raise_exception_on_error=False)
assert_false(p.is_valid())
assert_true(p.id is None or p.id < 0)
def setup():
"""No additional setup required."""
setup_module()
def test_retrieval_exception_raised():
import caosdb as h
from nose.tools import assert_true, assert_is_not_none, assert_equal # @UnresolvedImport
# special error: EntityDoesNotExistError def teardown():
try: """Delete everything."""
h.Property(name="Non-ExistentProperty").retrieve(unique=True, setup_module()
raise_exception_on_error=True)
assert_true(False)
except EntityDoesNotExistError as e:
print("print(" + str(id(e)) + ")")
print(e)
assert_is_not_none(e.get_entity())
# more general error: EntityError
try:
h.Property(name="Non-ExistentProperty").retrieve(unique=True,
raise_exception_on_error=True)
assert_true(False)
except EntityError as e:
print(e)
assert_is_not_none(e.get_entity())
assert_equal('Non-ExistentProperty', e.get_entity().name)
# most general error: TransactionError def test_retrieval_no_exception_raised():
try: """Test whether retrieval fails but error is suppressed."""
p = h.Property(name="TestNon-ExsistentProperty").retrieve(
unique=True, raise_exception_on_error=False)
assert not p.is_valid()
assert (p.id is None or p.id < 0)
def test_retrieval_exception_raised():
"""Test if a TransactionError with the correct child is raised, and if
the child has the correct super classes.
"""
propname = "TestNon-ExistentProperty"
with pytest.raises(TransactionError) as te:
h.Property(name="Non-ExistentProperty").retrieve(unique=True, h.Property(name="Non-ExistentProperty").retrieve(unique=True,
raise_exception_on_error=True) raise_exception_on_error=True)
assert_true(False) te = te.value
except EntityDoesNotExistError as e: assert len(te.get_errors()) == 1
print(e) ee = te.get_errors()[0]
assert_is_not_none(e.get_entities()) # Check for type incl. inheritance
print(e.get_entities()) assert isinstance(ee, EntityDoesNotExistError)
assert_is_not_none(e.get_entity()) assert isinstance(ee, EntityError)
print(e.get_entity()) assert isinstance(ee, TransactionError)
assert_equal(1, len(e.get_entities())) # Correct entity causing the error:
assert_equal('Non-ExistentProperty', e.get_entities()[0].name) assert not (ee.get_entity() is None)
assert ee.get_entity().name == propname
assert len(ee.get_entities()) == 1
assert ee.get_entities()[0].name == propname
def test_insertion_no_exception_raised(): def test_insertion_no_exception_raised():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment