Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
20deff4d
Commit
20deff4d
authored
4 years ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
TST: Continue sketch of unittest for new errors
parent
df460b03
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_error_handling.py
+54
-3
54 additions, 3 deletions
unittests/test_error_handling.py
with
54 additions
and
3 deletions
unittests/test_error_handling.py
+
54
−
3
View file @
20deff4d
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment