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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Python Integration Tests
Commits
973093a5
Commit
973093a5
authored
4 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
TST: Update test_error_stuff.py
parent
7b4d59ac
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_error_stuff.py
+166
-226
166 additions, 226 deletions
tests/test_error_stuff.py
with
166 additions
and
226 deletions
tests/test_error_stuff.py
+
166
−
226
View file @
973093a5
...
...
@@ -129,245 +129,185 @@ def test_insertion_with_invalid_parents():
def
test_insertion_with_invalid_properties
():
import
caosdb
as
h
# @UnresolvedImport
from
nose.tools
import
assert_false
,
assert_true
,
assert_is_not_none
,
assert_equal
try
:
try
:
h
.
execute_query
(
"
FIND NoTypeProperty
"
).
delete
()
except
BaseException
:
pass
with
pytest
.
raises
(
TransactionError
)
as
te
:
p
=
h
.
Property
(
name
=
"
NoTypeProperty
"
,
name
=
"
Test
NoTypeProperty
"
,
datatype
=
"
Text
"
).
add_property
(
id
=-
1
)
p
.
insert
(
raise_exception_on_error
=
True
)
raise
AssertionError
(
"
This should raise an UnqualifiedPropertiesError.
"
)
except
EntityError
as
e
:
assert_true
(
isinstance
(
e
,
UnqualifiedPropertiesError
))
assert_is_not_none
(
e
.
get_entity
())
assert_equal
(
e
.
get_entity
().
name
,
p
.
name
)
assert_true
(
e
.
get_entity
().
has_errors
())
assert_true
(
p
.
has_errors
())
assert_false
(
p
.
is_valid
())
assert_false
(
e
.
get_entity
().
is_valid
())
finally
:
try
:
p
.
delete
()
except
BaseException
:
pass
# TransactionError with ContainerError with
# UnqualifiedPropertiesError
upe
=
te
.
value
.
get_errors
()[
0
].
get_errors
()[
0
]
assert
isinstance
(
upe
,
UnqualifiedPropertiesError
)
assert
not
upe
.
get_entity
()
is
None
assert
upe
.
get_entity
().
name
==
p
.
name
assert
upe
.
get_entity
().
has_errors
()
assert
p
.
has_errors
()
assert
not
p
.
is_valid
()
assert
not
e
.
get_entity
().
is_valid
()
def
test_entity_does_not_exist
():
import
caosdb
as
h
# @UnresolvedImport
from
nose.tools
import
assert_true
,
assert_false
,
assert_equal
,
assert_is_not_none
"""
When retrieving a container with existing and non-existing
entities, only those that don
'
t exist should cause
EntityDoesNotExistErrors.
try
:
p1
=
h
.
Property
(
name
=
"
Non-ExistentProperty1
"
).
retrieve
(
raise_exception_on_error
=
False
)
p2
=
h
.
Property
(
name
=
"
Non-ExistentProperty2
"
).
retrieve
(
raise_exception_on_error
=
False
)
p3
=
h
.
Property
(
name
=
"
Non-ExistentProperty3
"
).
retrieve
(
raise_exception_on_error
=
False
)
assert_false
(
p1
.
is_valid
())
assert_true
(
p1
.
id
is
None
or
p1
.
id
<
0
)
assert_false
(
p2
.
is_valid
())
assert_true
(
p2
.
id
is
None
or
p2
.
id
<
0
)
assert_false
(
p3
.
is_valid
())
assert_true
(
p3
.
id
is
None
or
p3
.
id
<
0
)
pe
=
h
.
Property
(
name
=
"
ExistentProperty
"
,
datatype
=
"
text
"
).
insert
()
c
=
h
.
Container
().
extend
(
[
h
.
Property
(
name
=
"
Non-ExistentProperty1
"
),
h
.
Property
(
name
=
"
Non-ExistentProperty2
"
),
h
.
Property
(
name
=
"
Non-ExistentProperty3
"
),
h
.
Property
(
name
=
"
ExistentProperty
"
)])
try
:
c
.
retrieve
()
except
EntityDoesNotExistError
as
e
:
assert_equal
(
3
,
len
(
e
.
get_entities
()))
for
entity
in
e
.
get_entities
():
assert_is_not_none
(
entity
.
name
)
assert_true
(
entity
.
name
.
startswith
(
"
Non-ExistentProperty
"
))
finally
:
try
:
pe
.
delete
()
except
BaseException
:
pass
def
test_insert_existent_entity
():
import
caosdb
as
h
# @UnresolvedImport
from
nose.tools
import
assert_true
,
assert_false
,
assert_equal
,
assert_is_not_none
try
:
p1
=
h
.
Property
(
name
=
"
Non-ExistentProperty1
"
).
retrieve
(
raise_exception_on_error
=
False
)
p2
=
h
.
Property
(
name
=
"
Non-ExistentProperty2
"
).
retrieve
(
raise_exception_on_error
=
False
)
p3
=
h
.
Property
(
name
=
"
Non-ExistentProperty3
"
).
retrieve
(
raise_exception_on_error
=
False
)
assert_false
(
p1
.
is_valid
())
assert_true
(
p1
.
id
is
None
or
p1
.
id
<
0
)
assert_false
(
p2
.
is_valid
())
assert_true
(
p2
.
id
is
None
or
p2
.
id
<
0
)
assert_false
(
p3
.
is_valid
())
assert_true
(
p3
.
id
is
None
or
p3
.
id
<
0
)
pe
=
h
.
Property
(
name
=
"
ExistentProperty
"
,
datatype
=
"
text
"
).
insert
()
assert_true
(
pe
.
is_valid
())
c
=
h
.
Container
().
extend
(
[
h
.
Property
(
name
=
"
Non-ExistentProperty1
"
,
datatype
=
"
text
"
),
h
.
Property
(
name
=
"
Non-ExistentProperty2
"
,
datatype
=
"
text
"
),
h
.
Property
(
name
=
"
Non-ExistentProperty3
"
,
datatype
=
"
text
"
),
h
.
Property
(
name
=
"
ExistentProperty
"
,
datatype
=
"
text
"
)])
try
:
c
.
insert
(
unique
=
True
)
except
UniqueNamesError
as
e
:
assert_equal
(
1
,
len
(
e
.
get_entities
()))
for
entity
in
e
.
get_entities
():
assert_is_not_none
(
entity
.
name
)
assert_equal
(
pe
.
name
,
entity
.
name
)
finally
:
try
:
c
.
delete
()
except
BaseException
:
pass
try
:
pe
.
delete
()
except
BaseException
:
pass
try
:
p3
.
delete
()
except
BaseException
:
pass
try
:
p2
.
delete
()
except
BaseException
:
pass
try
:
p1
.
delete
()
except
BaseException
:
pass
def
test_double_insertion
():
import
caosdb
as
h
from
nose.tools
import
assert_true
,
assert_equal
,
assert_is_not_none
# @UnresolvedImport
c1
=
h
.
Container
()
try
:
c1
.
append
(
"""
p1
=
h
.
Property
(
name
=
"
TestNon-ExistentProperty1
"
).
retrieve
(
raise_exception_on_error
=
False
)
p2
=
h
.
Property
(
name
=
"
TestNon-ExistentProperty2
"
).
retrieve
(
raise_exception_on_error
=
False
)
p3
=
h
.
Property
(
name
=
"
TestNon-ExistentProperty3
"
).
retrieve
(
raise_exception_on_error
=
False
)
# None of them should exist
assert
not
p1
.
is_valid
()
assert
(
p1
.
id
is
None
or
p1
.
id
<
0
)
assert
not
p2
.
is_valid
()
assert
(
p2
.
id
is
None
or
p2
.
id
<
0
)
assert
not
p3
.
is_valid
()
assert
(
p3
.
id
is
None
or
p3
.
id
<
0
)
pe
=
h
.
Property
(
name
=
"
TestExistentProperty
"
,
datatype
=
"
text
"
).
insert
()
c
=
h
.
Container
().
extend
(
[
h
.
Property
(
name
=
"
SimpleTextProperty
"
,
description
=
"
simple text property (from test_error_stuff.py)
"
,
datatype
=
'
text
'
))
c1
.
append
(
name
=
"
TestNon-ExistentProperty1
"
),
h
.
Property
(
name
=
"
SimpleDoubleProperty
"
,
description
=
"
simple double property (from test_error_stuff.py)
"
,
datatype
=
'
double
'
))
c1
.
append
(
name
=
"
TestNon-ExistentProperty2
"
),
h
.
Property
(
name
=
"
SimpleIntegerProperty
"
,
description
=
"
simple integer property (from test_error_stuff.py)
"
,
datatype
=
'
integer
'
))
c1
.
append
(
name
=
"
TestNon-ExistentProperty3
"
),
h
.
Property
(
name
=
"
SimpleDatetimeProperty
"
,
description
=
"
simple datetime property (from test_error_stuff.py)
"
,
datatype
=
'
datetime
'
))
c1
.
append
(
h
.
RecordType
(
name
=
"
SimpleRecordType
"
,
description
=
"
simple recordType (from test_error_stuff.py)
"
)
.
add_property
(
name
=
'
SimpleTextProperty
'
)
.
add_property
(
name
=
'
SimpleDoubleProperty
'
)
.
add_property
(
name
=
'
SimpleIntegerProperty
'
)
.
add_property
(
name
=
'
SimpleDatetimeProperty
'
))
c1
.
insert
()
c2
=
h
.
Container
()
c2
.
append
(
name
=
"
TestExistentProperty
"
)])
with
pytest
.
raises
(
TransactionError
)
as
te
:
c
.
retrieve
()
te
=
te
.
value
assert
te
.
has_error
(
EntityDoesNotExistError
)
assert
not
pe
in
te
.
get_all_entities
()
for
p
in
(
p1
,
p2
,
p3
):
assert
p
in
te
.
get_all_entities
()
def
test_insert_existent_entity
():
"""
Insertion of an already existing entity should cause a
UniqueNamesError.
"""
p1
=
h
.
Property
(
name
=
"
TestNon-ExistentProperty1
"
).
retrieve
(
raise_exception_on_error
=
False
)
p2
=
h
.
Property
(
name
=
"
TestNon-ExistentProperty2
"
).
retrieve
(
raise_exception_on_error
=
False
)
p3
=
h
.
Property
(
name
=
"
TestNon-ExistentProperty3
"
).
retrieve
(
raise_exception_on_error
=
False
)
# None of them should exist
assert
not
p1
.
is_valid
()
assert
(
p1
.
id
is
None
or
p1
.
id
<
0
)
assert
not
p2
.
is_valid
()
assert
(
p2
.
id
is
None
or
p2
.
id
<
0
)
assert
not
p3
.
is_valid
()
assert
(
p3
.
id
is
None
or
p3
.
id
<
0
)
pe
=
h
.
Property
(
name
=
"
TestExistentProperty
"
,
datatype
=
"
text
"
).
insert
()
assert
pe
.
is_valid
()
c
=
h
.
Container
().
extend
(
[
h
.
Property
(
name
=
"
SimpleTextProperty
"
,
description
=
"
simple text property (from test_error_stuff.py)
"
,
datatype
=
'
text
'
))
c2
.
append
(
name
=
"
TestNon-ExistentProperty1
"
,
datatype
=
"
text
"
),
h
.
Property
(
name
=
"
SimpleDoubleProperty
"
,
description
=
"
simple double property (from test_error_stuff.py)
"
,
datatype
=
'
double
'
))
c2
.
append
(
name
=
"
TestNon-ExistentProperty2
"
,
datatype
=
"
text
"
),
h
.
Property
(
name
=
"
SimpleIntegerProperty
"
,
description
=
"
simple integer property (from test_error_stuff.py)
"
,
datatype
=
'
integer
'
))
c2
.
append
(
name
=
"
TestNon-ExistentProperty3
"
,
datatype
=
"
text
"
),
h
.
Property
(
name
=
"
SimpleDatetimeProperty
"
,
description
=
"
simple datetime property (from test_error_stuff.py)
"
,
datatype
=
'
datetime
'
))
c2
.
append
(
h
.
RecordType
(
name
=
"
SimpleRecordType
"
,
description
=
"
simple recordType (from test_error_stuff.py)
"
)
.
add_property
(
name
=
'
SimpleTextProperty
'
)
.
add_property
(
name
=
'
SimpleDoubleProperty
'
)
.
add_property
(
name
=
'
SimpleIntegerProperty
'
)
.
add_property
(
name
=
'
SimpleDatetimeProperty
'
))
try
:
c2
.
insert
()
except
TransactionError
as
te
:
assert_true
(
isinstance
(
te
,
EntityError
))
assert_true
(
isinstance
(
te
,
UniqueNamesError
))
assert_true
(
hasattr
(
te
,
'
get_errors
'
))
assert_is_not_none
(
te
.
get_errors
)
assert_is_not_none
(
te
.
get_errors
())
assert_true
(
hasattr
(
te
,
'
get_error
'
))
assert_is_not_none
(
te
.
get_error
)
assert_is_not_none
(
te
.
get_error
())
assert_true
(
hasattr
(
te
,
'
get_entities
'
))
assert_is_not_none
(
te
.
get_entities
)
assert_is_not_none
(
te
.
get_entities
())
assert_equal
(
5
,
len
(
te
.
get_entities
()))
assert_true
(
hasattr
(
te
,
'
get_container
'
))
assert_is_not_none
(
te
.
get_container
)
assert_is_not_none
(
te
.
get_container
())
assert_equal
(
c2
,
te
.
get_container
())
finally
:
try
:
c2
.
delete
()
except
BaseException
:
pass
try
:
c1
.
delete
()
except
BaseException
:
pass
name
=
"
TestExistentProperty
"
,
datatype
=
"
text
"
)])
with
pytest
.
raises
(
TransActionError
)
as
te
:
c
.
insert
(
unique
=
True
)
te
=
te
.
value
assert
te
.
has_error
(
UniqueNamesError
)
une
=
te
.
get_errors
()[
0
].
get_errors
()[
0
]
assert
len
(
une
.
get_entities
)
==
1
assert
not
une
.
get_entity
()
is
None
assert
pe
.
name
==
une
.
get_entity
().
name
for
p
in
(
p1
,
p2
,
p3
):
assert
not
p
in
te
.
get_all_entities
()
def
test_double_insertion
():
c1
=
h
.
Container
()
c1
.
append
(
h
.
Property
(
name
=
"
TestSimpleTextProperty
"
,
description
=
"
simple text property (from test_error_stuff.py)
"
,
datatype
=
'
text
'
))
c1
.
append
(
h
.
Property
(
name
=
"
TestSimpleDoubleProperty
"
,
description
=
"
simple double property (from test_error_stuff.py)
"
,
datatype
=
'
double
'
))
c1
.
append
(
h
.
Property
(
name
=
"
TestSimpleIntegerProperty
"
,
description
=
"
simple integer property (from test_error_stuff.py)
"
,
datatype
=
'
integer
'
))
c1
.
append
(
h
.
Property
(
name
=
"
TestSimpleDatetimeProperty
"
,
description
=
"
simple datetime property (from test_error_stuff.py)
"
,
datatype
=
'
datetime
'
))
c1
.
append
(
h
.
RecordType
(
name
=
"
TestSimpleRecordType
"
,
description
=
"
simple recordType (from test_error_stuff.py)
"
).
add_property
(
name
=
'
TestSimpleTextProperty
'
).
add_property
(
name
=
'
TestSimpleDoubleProperty
'
).
add_property
(
name
=
'
TestSimpleIntegerProperty
'
).
add_property
(
name
=
'
TestSimpleDatetimeProperty
'
))
c1
.
insert
()
c2
=
h
.
Container
()
c2
.
append
(
h
.
Property
(
name
=
"
TestSimpleTextProperty
"
,
description
=
"
simple text property (from test_error_stuff.py)
"
,
datatype
=
'
text
'
))
c2
.
append
(
h
.
Property
(
name
=
"
TestSimpleDoubleProperty
"
,
description
=
"
simple double property (from test_error_stuff.py)
"
,
datatype
=
'
double
'
))
c2
.
append
(
h
.
Property
(
name
=
"
TestSimpleIntegerProperty
"
,
description
=
"
simple integer property (from test_error_stuff.py)
"
,
datatype
=
'
integer
'
))
c2
.
append
(
h
.
Property
(
name
=
"
TestSimpleDatetimeProperty
"
,
description
=
"
simple datetime property (from test_error_stuff.py)
"
,
datatype
=
'
datetime
'
))
c2
.
append
(
h
.
RecordType
(
name
=
"
TestSimpleRecordType
"
,
description
=
"
simple recordType (from test_error_stuff.py)
"
).
add_property
(
name
=
'
TestSimpleTextProperty
'
).
add_property
(
name
=
'
TestSimpleDoubleProperty
'
).
add_property
(
name
=
'
TestSimpleIntegerProperty
'
).
add_property
(
name
=
'
TestSimpleDatetimeProperty
'
))
with
pytest
.
raises
(
TransActionError
)
as
te
:
c2
.
insert
()
te
=
te
.
value
assert
te
.
has_error
(
UniqueNamesError
)
# c2 caused the ContainerError
assert
te
.
get_errors
()[
0
].
get_entity
()
==
c2
# exactly 5 faulty entities in c2
assert
len
(
te
.
get_errors
()[
0
].
get_entities
())
==
5
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