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
No related branches found
No related tags found
No related merge requests found
...@@ -29,9 +29,10 @@ children. ...@@ -29,9 +29,10 @@ children.
import caosdb as db import caosdb as db
from caosdb.common.models import raise_errors from caosdb.common.models import raise_errors
# TODO: Import the relevant error classes once they have been finalized. # TODO: Import the relevant error classes once they have been finalized.
from caosdb.exceptions import (EntityDoesNotExistError, from caosdb.exceptions import (AuthorizationException,
EntityDoesNotExistError, EntityError,
EntityHasNoDatatypeError, EntityHasNoDatatypeError,
TransactionError) TransactionError, UniqueNamesError)
from pytest import raises from pytest import raises
...@@ -68,29 +69,55 @@ def test_entity_does_not_exist_error(): ...@@ -68,29 +69,55 @@ def test_entity_does_not_exist_error():
code = 101 code = 101
ent = _add_error_message_to_entity(db.Entity(name="TestEnt"), ent = _add_error_message_to_entity(db.Entity(name="TestEnt"),
code) code)
db.Property(name="TestProp"),
code)
with raises(TransactionError) as e: with raises(TransactionError) as e:
raise_errors(ent) raise_errors(ent)
# There should be exactly one child # There should be exactly one child
assert len(e.errors) == 1 assert len(e.errors) == 1
err=e.errors[0] err = e.errors[0]
# check type and entity of only child # check type and entity of only child
assert isinstance(err, EntityDoesNotExistError) assert isinstance(err, EntityDoesNotExistError)
assert err.entity.name == ent.name assert err.entity.name == ent.name
# TODO: remaining single error tests # TODO: remaining single error tests
def test_entity_error(): def test_entity_error():
"""Code 0; most basic.""" """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(): def test_unique_names_error():
"""Code 152; name is not unique""" """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(): def test_authorization_exception():
"""Code 403; transaction not allowed""" """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 #################### # #################### Children with children ####################
...@@ -98,9 +125,9 @@ def test_authorization_exception(): ...@@ -98,9 +125,9 @@ def test_authorization_exception():
def test_unqualified_parents_error(): def test_unqualified_parents_error():
"""Code 116; parent does not exist""" """Code 116; parent does not exist"""
code=116 code = 116
entity_does_not_exist_code=101 entity_does_not_exist_code = 101
parent=_add_error_message_to_entity( parent = _add_error_message_to_entity(
db.RecordType(name="TestParent"), db.RecordType(name="TestParent"),
entity_does_not_exist_code) entity_does_not_exist_code)
rec = _add_error_message_to_entity(db.Record(name="TestRecord"), rec = _add_error_message_to_entity(db.Record(name="TestRecord"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment