Skip to content
Snippets Groups Projects
Commit 20deff4d authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

TST: Continue sketch of unittest for new errors

parent df460b03
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,8 @@ children.
import caosdb as db
from caosdb.common.models import raise_errors
# TODO: Import the relevant error classes once they have been finalized.
from caosdb.exceptions import (AuthorizationException,
from caosdb.exceptions import (AmbiguityException,
AuthorizationException,
EntityDoesNotExistError, EntityError,
EntityHasNoDatatypeError,
TransactionError, UniqueNamesError)
......@@ -171,7 +172,7 @@ def test_parent_and_properties_errors():
prop_code = 114
parent_code = 116
entity_code = 0
no_entity_code = 0
no_entity_code = 101
parent = _add_error_message_to_entity(
db.RecordType(name="TestParent"), no_entity_code)
prop1 = _add_error_message_to_entity(db.Property(
......@@ -200,7 +201,7 @@ def test_container_with_faulty_elements():
name_code = 152
auth_code = 403
entity_code = 0
no_entity_code = 0
no_entity_code = 101
# Broken parents and properties
parent = _add_error_message_to_entity(
db.RecordType(name="TestParent"), no_entity_code)
......@@ -228,3 +229,53 @@ def test_container_with_faulty_elements():
raise_errors(cont)
# TODO: Check whether all errors and all broken entities are
# listed correctly. The healthy entities must not appear.
def test_convenience_functions():
"""Test whether get_error and and get_entity work and break as
intended, and whether has_error works properly.
"""
# Only one child
no_entity_code = 101
ent = _add_error_message_to_entity(
db.Entity(name="TestEnt"), no_entity_code)
with raises(TransactionError) as e:
raise_errors(ent)
te = e.value
# Works since there is exactly one child
assert te.get_entity().name == ent.name
assert te.get_error() == ent.get_errors()[0]
# Has to have this
assert te.has_error(EntityDoesNotExistError)
# EntityDoesNotExistError is an EntityError
assert te.has_error(EntityError)
# Shouldn't be there
assert not te.has_error(UniqueNamesError)
# Two children
prop_code = 114
parent_code = 116
entity_code = 0
parent = _add_error_message_to_entity(
db.RecordType(name="TestParent"), no_entity_code)
prop1 = _add_error_message_to_entity(db.Property(
name="TestProp1"), entity_code)
prop2 = _add_error_message_to_entity(db.Property(
name="TestProp2"), no_entity_code)
rec = _add_error_message_to_entity(db.Record(name="TestRecord"),
prop_code)
rec = _add_error_message_to_entity(rec, parent_code)
rec.add_parent(parent)
rec.add_property(prop1).add_property(prop2)
with raises(TransactionError) as e:
raise_errors(rec)
te = e.value
# Two children, should raise an Error
with raises(AmbiguityException):
te.get_error()
with raises(AmbiguityException):
te.get_entity()
for error_t in [EntityDoesNotExistError, UnqualifiedParentsError,
UnqualifiedPropertiesError]:
assert te.has_error(error_t)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment