1414
1515
1616class CampaignStatus (Enum ):
17- draft = 1
18- producing = 2
19- closed = 3
17+ DRAFT = 1
18+ PRODUCING = 2
19+ CLOSED = 3
2020
2121
2222class CampaignMachine (StateMachine ):
2323 "A workflow machine"
2424
2525 states = States .from_enum (
26- CampaignStatus , initial = CampaignStatus .draft , final = CampaignStatus .closed
26+ CampaignStatus ,
27+ initial = CampaignStatus .DRAFT ,
28+ final = CampaignStatus .CLOSED ,
29+ use_enum_instance = True ,
2730 )
2831
29- add_job = states .draft .to (states .draft ) | states .producing .to (states .producing )
30- produce = states .draft .to (states .producing )
31- deliver = states .producing .to (states .closed )
32+ add_job = states .DRAFT .to (states .DRAFT ) | states .PRODUCING .to (states .PRODUCING )
33+ produce = states .DRAFT .to (states .PRODUCING )
34+ deliver = states .PRODUCING .to (states .CLOSED )
3235
3336
3437# %%
3538# Asserting campaign machine declaration
3639
37- assert CampaignMachine .draft .initial
38- assert not CampaignMachine .draft .final
40+ assert CampaignMachine .DRAFT .initial
41+ assert not CampaignMachine .DRAFT .final
3942
40- assert not CampaignMachine .producing .initial
41- assert not CampaignMachine .producing .final
43+ assert not CampaignMachine .PRODUCING .initial
44+ assert not CampaignMachine .PRODUCING .final
4245
43- assert not CampaignMachine .closed .initial
44- assert CampaignMachine .closed .final
46+ assert not CampaignMachine .CLOSED .initial
47+ assert CampaignMachine .CLOSED .final
4548
4649
4750# %%
@@ -50,8 +53,8 @@ class CampaignMachine(StateMachine):
5053sm = CampaignMachine ()
5154res = sm .send ("produce" )
5255
53- assert sm .draft .is_active is False
54- assert sm .producing .is_active is True
55- assert sm .closed .is_active is False
56- assert sm .current_state == sm .producing
57- assert sm .current_state_value == CampaignStatus .producing
56+ assert sm .DRAFT .is_active is False
57+ assert sm .PRODUCING .is_active is True
58+ assert sm .CLOSED .is_active is False
59+ assert sm .current_state == sm .PRODUCING
60+ assert sm .current_state_value == CampaignStatus .PRODUCING
0 commit comments