From 8328e66ac30f5954aecb6242d08a6ed7db386187 Mon Sep 17 00:00:00 2001 From: fspreck <f.spreckelsen@indiscale.com> Date: Thu, 25 Jun 2020 14:37:42 +0200 Subject: [PATCH] TST: More single error test cases. --- unittests/test_error_handling.py | 45 +++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/unittests/test_error_handling.py b/unittests/test_error_handling.py index 9962a0df..30912e75 100644 --- a/unittests/test_error_handling.py +++ b/unittests/test_error_handling.py @@ -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,29 +69,55 @@ 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 assert len(e.errors) == 1 - err=e.errors[0] + err = e.errors[0] # check type and entity of only child assert isinstance(err, EntityDoesNotExistError) 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 #################### @@ -98,9 +125,9 @@ def test_authorization_exception(): def test_unqualified_parents_error(): """Code 116; parent does not exist""" - code=116 - entity_does_not_exist_code=101 - parent=_add_error_message_to_entity( + code = 116 + entity_does_not_exist_code = 101 + parent = _add_error_message_to_entity( db.RecordType(name="TestParent"), entity_does_not_exist_code) rec = _add_error_message_to_entity(db.Record(name="TestRecord"), -- GitLab