Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Python Integration Tests
Commits
7b4d59ac
Commit
7b4d59ac
authored
5 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Update more tests
parent
661f2c5a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_error_stuff.py
+34
-55
34 additions, 55 deletions
tests/test_error_stuff.py
with
34 additions
and
55 deletions
tests/test_error_stuff.py
+
34
−
55
View file @
7b4d59ac
...
@@ -31,9 +31,12 @@ Created on 19.02.2015.
...
@@ -31,9 +31,12 @@ Created on 19.02.2015.
"""
"""
import
caosdb
as
h
import
caosdb
as
h
from
caosdb.exceptions
import
(
EntityDoesNotExistError
,
from
caosdb.exceptions
import
(
ContainerError
,
UniqueNamesError
,
TransactionError
,
EntityError
,
EntityDoesNotExistError
,
UnqualifiedPropertiesError
,
EntityHasNoDatatypeError
,
EntityHasNoDatatypeError
,
UniqueNamesError
,
TransactionError
,
EntityError
,
UnqualifiedPropertiesError
,
UnqualifiedParentsError
)
UnqualifiedParentsError
)
import
pytest
import
pytest
...
@@ -72,9 +75,11 @@ def test_retrieval_exception_raised():
...
@@ -72,9 +75,11 @@ def test_retrieval_exception_raised():
with
pytest
.
raises
(
TransactionError
)
as
te
:
with
pytest
.
raises
(
TransactionError
)
as
te
:
h
.
Property
(
name
=
"
Non-ExistentProperty
"
).
retrieve
(
unique
=
True
,
h
.
Property
(
name
=
"
Non-ExistentProperty
"
).
retrieve
(
unique
=
True
,
raise_exception_on_error
=
True
)
raise_exception_on_error
=
True
)
te
=
te
.
value
# retrieve returns a container, so treat that one separately
assert
len
(
te
.
get_errors
())
==
1
ce
=
te
.
value
.
get_errors
()[
0
]
ee
=
te
.
get_errors
()[
0
]
assert
isinstance
(
ce
,
ContainerError
)
assert
len
(
ce
.
get_errors
())
==
1
ee
=
ce
.
get_errors
()[
0
]
# Check for type incl. inheritance
# Check for type incl. inheritance
assert
isinstance
(
ee
,
EntityDoesNotExistError
)
assert
isinstance
(
ee
,
EntityDoesNotExistError
)
assert
isinstance
(
ee
,
EntityError
)
assert
isinstance
(
ee
,
EntityError
)
...
@@ -87,66 +92,40 @@ def test_retrieval_exception_raised():
...
@@ -87,66 +92,40 @@ def test_retrieval_exception_raised():
def
test_insertion_no_exception_raised
():
def
test_insertion_no_exception_raised
():
import
caosdb
as
h
"""
Test whether insertion fails but no error is raised.
"""
from
nose.tools
import
assert_false
,
assert_true
# @UnresolvedImport
p
=
h
.
Property
(
name
=
"
TestNoTypeProperty
"
).
insert
(
try
:
p
=
h
.
Property
(
name
=
"
NoTypeProperty
"
).
insert
(
raise_exception_on_error
=
False
)
raise_exception_on_error
=
False
)
assert_false
(
p
.
is_valid
())
assert
not
p
.
is_valid
()
assert_true
(
p
.
id
is
None
or
p
.
id
<
0
)
assert
(
p
.
id
is
None
or
p
.
id
<
0
)
finally
:
try
:
p
.
delete
()
except
BaseException
:
pass
def
test_insertion_exception_raised
():
def
test_insertion_exception_raised
():
import
caosdb
as
h
"""
Test insertion of a property with missing datatype.
"""
from
nose.tools
import
assert_true
# @UnresolvedImport
p
=
h
.
Property
(
name
=
"
TestNoTypeProperty
"
)
with
pytest
.
raises
(
TransactionError
)
as
te
:
try
:
p
=
h
.
Property
(
name
=
"
NoTypeProperty
"
)
p
.
insert
(
raise_exception_on_error
=
True
)
p
.
insert
(
raise_exception_on_error
=
True
)
assert_true
(
False
)
assert
te
.
value
.
has_error
(
EntityHasNoDatatypeError
)
except
EntityError
as
e
:
print
(
e
)
finally
:
try
:
p
.
delete
()
except
BaseException
:
pass
def
test_insertion_with_invalid_parents
():
def
test_insertion_with_invalid_parents
():
import
caosdb
as
h
with
pytest
.
raises
(
TransactionError
)
as
te
:
# @UnresolvedImport
from
nose.tools
import
assert_false
,
assert_true
,
assert_is_not_none
,
assert_equal
try
:
p
=
h
.
Property
(
p
=
h
.
Property
(
name
=
"
NoTypeProperty
"
,
name
=
"
Test
NoTypeProperty
"
,
datatype
=
"
Text
"
).
add_parent
(
datatype
=
"
Text
"
).
add_parent
(
id
=-
1
)
id
=-
1
)
p
.
insert
(
raise_exception_on_error
=
True
)
p
.
insert
(
raise_exception_on_error
=
True
)
assert_true
(
False
)
# TransactionError with ContainerError with
except
EntityError
as
e
:
# UnqualifiedParentsError
print
(
e
)
upe
=
te
.
value
.
get_errors
()[
0
].
get_errors
()[
0
]
assert_true
(
isinstance
(
e
,
UnqualifiedParentsError
))
print
(
upe
)
assert_is_not_none
(
e
.
get_entity
())
assert
isinstance
(
upe
,
UnqualifiedParentsError
)
assert_equal
(
e
.
get_entity
().
name
,
p
.
name
)
assert
not
upe
.
get_entity
()
is
None
assert_equal
(
e
.
get_entity
().
id
,
p
.
id
)
assert
upe
.
get_entity
().
name
==
p
.
name
assert_true
(
e
.
get_entity
().
has_errors
())
assert
upe
.
get_entity
().
id
==
p
.
id
assert_false
(
p
.
is_valid
())
assert
upe
.
get_entity
().
has_errors
()
assert_false
(
e
.
get_entity
().
is_valid
())
assert
not
p
.
is_valid
()
assert_is_not_none
(
e
.
get_entities
())
assert
not
upe
.
get_entity
().
is_valid
()
finally
:
assert
nt
upe
.
get_entities
()
is
not
None
try
:
p
.
delete
()
except
BaseException
:
pass
def
test_insertion_with_invalid_properties
():
def
test_insertion_with_invalid_properties
():
...
...
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