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
a0f4c836
Verified
Commit
a0f4c836
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
STY: autopep8'ed test_state.py
parent
704adae7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
F fsm
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_state.py
+51
-12
51 additions, 12 deletions
tests/test_state.py
with
51 additions
and
12 deletions
tests/test_state.py
+
51
−
12
View file @
a0f4c836
import
pytest
import
caosdb
as
db
def
teardown_module
():
d
=
db
.
execute_query
(
"
FIND ENTITY WITH ID > 99
"
)
if
len
(
d
)
>
0
:
d
.
delete
(
flags
=
{
"
forceFinalState
"
:
"
true
"
})
def
setup_module
():
teardown_module
()
db
.
RecordType
(
"
State
"
).
insert
()
...
...
@@ -20,25 +22,43 @@ def setup_module():
db
.
Record
(
"
State2
"
).
add_parent
(
"
State
"
).
insert
()
db
.
Record
(
"
State3
"
).
add_parent
(
"
State
"
).
insert
()
# 1->
db
.
Record
(
"
Transition1
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State1
"
).
add_property
(
"
to
"
,
"
State2
"
).
insert
()
db
.
Record
(
"
Transition1
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State1
"
).
add_property
(
"
to
"
,
"
State2
"
).
insert
()
# 2->3
db
.
Record
(
"
Transition2
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State2
"
).
add_property
(
"
to
"
,
"
State3
"
).
insert
()
db
.
Record
(
"
Transition2
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State2
"
).
add_property
(
"
to
"
,
"
State3
"
).
insert
()
# 3->1
db
.
Record
(
"
Transition3
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State3
"
).
add_property
(
"
to
"
,
"
State1
"
).
insert
()
db
.
Record
(
"
Transition3
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State3
"
).
add_property
(
"
to
"
,
"
State1
"
).
insert
()
# 2->2
db
.
Record
(
"
Transition4
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State2
"
).
add_property
(
"
to
"
,
"
State2
"
).
insert
()
db
.
Record
(
"
Transition4
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State2
"
).
add_property
(
"
to
"
,
"
State2
"
).
insert
()
db
.
Record
(
"
Model1
"
).
add_parent
(
"
StateModel
"
).
add_property
(
"
Transition
"
,
datatype
=
db
.
LIST
(
"
Transition
"
),
value
=
[
"
Transition1
"
,
"
Transition2
"
,
"
Transition3
"
,
"
Transition4
"
]).
add_property
(
"
initial
"
,
"
State1
"
).
add_property
(
"
final
"
,
"
State1
"
).
insert
()
db
.
Record
(
"
Model1
"
).
add_parent
(
"
StateModel
"
).
add_property
(
"
Transition
"
,
datatype
=
db
.
LIST
(
"
Transition
"
),
value
=
[
"
Transition1
"
,
"
Transition2
"
,
"
Transition3
"
,
"
Transition4
"
]).
add_property
(
"
initial
"
,
"
State1
"
).
add_property
(
"
final
"
,
"
State1
"
).
insert
()
def
teardown
():
d
=
db
.
execute_query
(
"
FIND TestRT
"
)
if
len
(
d
)
>
0
:
d
.
delete
(
flags
=
{
"
forceFinalState
"
:
"
true
"
})
def
setup
():
teardown
()
db
.
RecordType
(
"
TestRT
"
).
insert
()
def
test_state_message
():
rec
=
db
.
Record
()
rec
.
add_parent
(
"
TestRT
"
)
...
...
@@ -53,6 +73,7 @@ def test_state_message():
assert
rec_retrieve
.
get_property
(
"
State
"
)
is
None
assert
rec_retrieve
.
state
==
rec
.
state
def
test_state_query
():
rec
=
db
.
Record
()
rec
.
add_parent
(
"
TestRT
"
)
...
...
@@ -60,7 +81,10 @@ def test_state_query():
rec
.
insert
()
assert
rec
.
get_property
(
"
State
"
)
is
None
assert
db
.
execute_query
(
"
FIND TestRT WITH State = State1
"
,
unique
=
True
).
id
==
rec
.
id
assert
db
.
execute_query
(
"
FIND TestRT WITH State = State1
"
,
unique
=
True
).
id
==
rec
.
id
def
test_state_transition
():
rec
=
db
.
Record
()
...
...
@@ -74,6 +98,7 @@ def test_state_transition():
rec_retrieve
=
db
.
Record
.
retrieve
(
rec
.
id
)
assert
rec_retrieve
.
state
==
rec_update
.
state
def
test_transition_not_allowed
():
"""
unallowed transitions return errors and do not update the entity
"""
rec
=
db
.
Record
()
...
...
@@ -83,14 +108,17 @@ def test_transition_not_allowed():
rec_insert
.
state
=
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State3
"
)
with
pytest
.
raises
(
db
.
TransactionError
):
rec_update
=
rec_insert
.
update
(
sync
=
False
,
raise_exception_on_error
=
False
)
rec_update
=
rec_insert
.
update
(
sync
=
False
,
raise_exception_on_error
=
False
)
assert
len
(
rec_update
.
get_errors
())
==
1
assert
rec_update
.
get_errors
()[
0
].
description
==
"
Transition not allowed.
"
assert
rec_update
.
get_errors
(
)[
0
].
description
==
"
Transition not allowed.
"
db
.
common
.
models
.
raise_errors
(
rec_update
)
rec_retrieve
=
db
.
Record
.
retrieve
(
rec_insert
.
id
)
assert
rec_retrieve
.
state
==
rec
.
state
def
test_wrong_initial
():
"""
the first state has to be an initial state
"""
rec
=
db
.
Record
()
...
...
@@ -102,6 +130,7 @@ def test_wrong_initial():
assert
len
(
rec
.
get_errors
())
==
1
assert
rec
.
get_errors
()[
0
].
description
==
"
Initial state not allowed.
"
def
test_wrong_final
():
"""
deletion of the entity or the state is only possible in final states
"""
rec
=
db
.
Record
()
...
...
@@ -124,6 +153,7 @@ def test_wrong_final():
rec
.
update
()
rec
.
delete
()
def
test_multiple_states
():
"""
currently, only one state is allowed
"""
rec
=
db
.
Record
()
...
...
@@ -131,10 +161,12 @@ def test_multiple_states():
state1
=
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State1
"
)
state2
=
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State2
"
)
class
TestState
:
def
to_xml
(
self
,
xml
):
xml
.
append
(
state1
.
to_xml
())
xml
.
append
(
state2
.
to_xml
())
def
clear_server_messages
(
self
):
pass
rec
.
messages
=
TestState
()
...
...
@@ -142,6 +174,7 @@ def test_multiple_states():
rec_insert
=
rec
.
insert
(
sync
=
False
)
print
(
rec_insert
)
def
test_broken_state_missing_model
():
rec
=
db
.
Record
()
rec
.
add_parent
(
"
TestRT
"
)
...
...
@@ -151,6 +184,7 @@ def test_broken_state_missing_model():
assert
len
(
rec
.
get_errors
())
==
1
assert
rec
.
get_errors
()[
0
].
description
==
"
State model not specified.
"
def
test_broken_state_missing_state_name
():
rec
=
db
.
Record
()
rec
.
add_parent
(
"
TestRT
"
)
...
...
@@ -160,6 +194,7 @@ def test_broken_state_missing_state_name():
assert
len
(
rec
.
get_errors
())
==
1
assert
rec
.
get_errors
()[
0
].
description
==
"
State not specified.
"
def
test_state_not_in_state_model
():
rec
=
db
.
Record
()
rec
.
add_parent
(
"
TestRT
"
)
...
...
@@ -167,7 +202,9 @@ def test_state_not_in_state_model():
with
pytest
.
raises
(
db
.
TransactionError
):
rec
.
insert
()
assert
len
(
rec
.
get_errors
())
==
1
assert
rec
.
get_errors
()[
0
].
description
==
"
State does not exist in this StateModel.
"
assert
rec
.
get_errors
()[
0
].
description
==
"
State does not exist in this StateModel.
"
def
test_transition_with_out_state_change
():
rec
=
db
.
Record
()
...
...
@@ -177,12 +214,14 @@ def test_transition_with_out_state_change():
rec_insert
=
rec
.
insert
(
sync
=
False
)
# first update attempt (should fail, because 1->1 not allowed)
rec_insert
.
description
=
"
updated description 1
"
rec_insert
.
description
=
"
updated description 1
"
with
pytest
.
raises
(
db
.
TransactionError
):
# transition 1 -> 1 not allowed
rec_update
=
rec_insert
.
update
(
sync
=
False
,
raise_exception_on_error
=
False
)
rec_update
=
rec_insert
.
update
(
sync
=
False
,
raise_exception_on_error
=
False
)
assert
len
(
rec_update
.
get_errors
())
==
1
assert
rec_update
.
get_errors
()[
0
].
description
==
"
Transition not allowed.
"
assert
rec_update
.
get_errors
(
)[
0
].
description
==
"
Transition not allowed.
"
db
.
common
.
models
.
raise_errors
(
rec_update
)
# second update with transition to state2
...
...
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