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
704adae7
Verified
Commit
704adae7
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
More tests
parent
c07d0635
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
-2
51 additions, 2 deletions
tests/test_state.py
with
51 additions
and
2 deletions
tests/test_state.py
+
51
−
2
View file @
704adae7
...
...
@@ -19,11 +19,16 @@ def setup_module():
db
.
Record
(
"
State1
"
).
add_parent
(
"
State
"
).
insert
()
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
()
# 2->3
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
()
# 2->2
db
.
Record
(
"
Transition4
"
).
add_parent
(
"
Transition
"
).
add_property
(
"
from
"
,
"
State2
"
).
add_property
(
"
to
"
,
"
State2
"
).
insert
()
db
.
Record
(
"
Model1
"
).
add_parent
(
"
StateModel
"
).
add_property
(
"
State
"
,
datatype
=
db
.
LIST
(
"
State
"
),
value
=
[
"
State1
"
,
"
State2
"
,
"
State3
"
]).
add_property
(
"
Transition
"
,
datatype
=
db
.
LIST
(
"
Transition
"
),
value
=
[
"
Transition1
"
,
"
Transition2
"
,
"
Transition3
"
]).
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
"
)
...
...
@@ -78,7 +83,10 @@ 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
)
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.
"
db
.
common
.
models
.
raise_errors
(
rec_update
)
rec_retrieve
=
db
.
Record
.
retrieve
(
rec_insert
.
id
)
assert
rec_retrieve
.
state
==
rec
.
state
...
...
@@ -160,3 +168,44 @@ def test_state_not_in_state_model():
rec
.
insert
()
assert
len
(
rec
.
get_errors
())
==
1
assert
rec
.
get_errors
()[
0
].
description
==
"
State does not exist in this StateModel.
"
def
test_transition_with_out_state_change
():
rec
=
db
.
Record
()
rec
.
description
=
"
old description
"
rec
.
add_parent
(
"
TestRT
"
)
rec
.
state
=
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State1
"
)
rec_insert
=
rec
.
insert
(
sync
=
False
)
# first update attempt (should fail, because 1->1 not allowed)
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
)
assert
len
(
rec_update
.
get_errors
())
==
1
assert
rec_update
.
get_errors
()[
0
].
description
==
"
Transition not allowed.
"
db
.
common
.
models
.
raise_errors
(
rec_update
)
# second update with transition to state2
rec_update
=
db
.
Record
(
id
=
rec_insert
.
id
).
retrieve
()
print
(
rec_update
)
assert
rec_update
.
state
==
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State1
"
)
assert
rec_update
.
description
==
"
old description
"
rec_update
.
description
=
"
updated description 2
"
rec_update
.
state
=
db
.
State
(
name
=
"
State2
"
,
model
=
"
Model1
"
)
# transition 1 -> 2 is allowed.
rec_update
.
update
()
# third update without state change
rec_update
=
db
.
Record
(
id
=
rec_insert
.
id
).
retrieve
()
print
(
rec_update
)
assert
rec_update
.
state
==
db
.
State
(
model
=
"
Model1
"
,
name
=
"
State2
"
)
assert
rec_update
.
description
==
"
updated description 2
"
rec_update
.
description
=
"
updated description 3
"
# transition 2 -> 2 is also allowed.
rec_update
.
update
()
rec_final
=
db
.
Record
.
retrieve
(
rec_insert
.
id
)
assert
rec_final
.
description
==
"
updated description 3
"
assert
rec_final
.
state
==
db
.
State
(
model
=
"
Model1
"
,
name
=
"
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