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

TST: More single error test cases.

parent d8bde631
Branches
Tags
No related merge requests found
......@@ -29,9 +29,10 @@ 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 (EntityDoesNotExistError,
from caosdb.exceptions import (AuthorizationException,
EntityDoesNotExistError, EntityError,
EntityHasNoDatatypeError,
TransactionError)
TransactionError, UniqueNamesError)
from pytest import raises
......@@ -68,9 +69,6 @@ def test_entity_does_not_exist_error():
code = 101
ent = _add_error_message_to_entity(db.Entity(name="TestEnt"),
code)
db.Property(name="TestProp"),
code)
with raises(TransactionError) as e:
raise_errors(ent)
# There should be exactly one child
......@@ -81,16 +79,45 @@ def test_entity_does_not_exist_error():
assert err.entity.name == ent.name
# TODO: remaining single error tests
def test_entity_error():
"""Code 0; most basic."""
code = 0
ent = _add_error_message_to_entity(db.Entity(name="TestEnt"),
code)
with raises(TransactionError) as e:
raise_errors(e)
assert len(e.errors) == 1
err = e.errors[0]
assert isinstance(err, EntityError)
assert err.entity.name == ent.name
def test_unique_names_error():
"""Code 152; name is not unique"""
code = 152
ent = _add_error_message_to_entity(db.Entity(name="TestEnt"),
code)
with raises(TransactionError) as e:
raise_errors(ent)
assert len(e.errors) == 1
err = e.errors[0]
assert isinstance(err, UniqueNamesError)
assert err.entity.name == ent.name
def test_authorization_exception():
"""Code 403; transaction not allowed"""
code = 403
ent = _add_error_message_to_entity(db.Entity(name="TestEnt"),
code)
with raises(TransactionError) as e:
raise_errors(ent)
assert len(e.errors) == 1
err = e.errors[0]
assert isinstance(err, AuthorizationException)
assert err.entity.name == ent.name
# #################### Children with children ####################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment