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
8328e66a
Commit
8328e66a
authored
4 years ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
TST: More single error test cases.
parent
d8bde631
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
+36
-9
36 additions, 9 deletions
unittests/test_error_handling.py
with
36 additions
and
9 deletions
unittests/test_error_handling.py
+
36
−
9
View file @
8328e66a
...
...
@@ -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
"
),
...
...
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