class OrderEventType(EventType): """ Order event type. Models the user journey through specifying an order for a pizza as described here: https://globality.atlassian.net/wiki/spaces/GLOB/pages/917733426/Product+Spec+Ordering+a+Pizza """ # NB: Our state machines always start with an initial event OrderInitialized = event_info(follows=nothing(), ) PizzaCreated = event_info(follows=any_of( "OrderInitialized", "PizzaCustomizationFinished", ), ) PizzaToppingAdded = event_info(follows=any_of( "PizzaCreated", "PizzaToppingAdded", ), ) PizzaCustomizationFinished = event_info(follows=any_of( "PizzaToppingAdded", ), ) OrderDeliveryDetailsAdded = event_info( follows=event("PizzaCustomizationFinished"), ) OrderSubmitted = event_info(follows=event("OrderDeliveryDetailsAdded"), ) OrderSatisfied = event_info(follows=event("OrderSubmitted"), ) OrderFulfilled = event_info(follows=event("OrderSubmitted"), )
class SimpleTestObjectEventType(EventType): CREATED = event_info( follows=nothing(), accumulate=keep(), ) READY = event_info( follows=event("CREATED"), accumulate=keep(), ) DONE = event_info( follows=event("READY"), accumulate=keep(), )
def test_all_of_nothing(): transition = all_of( nothing(), nothing(), ) assert_that( bool(transition), is_(equal_to(False)), ) assert_that( transition(TaskEventType, [TaskEventType.CREATED, TaskEventType.ASSIGNED]), is_(equal_to(False)), ) assert_that( transition(TaskEventType, [TaskEventType.CREATED]), is_(equal_to(False)), ) assert_that( transition(TaskEventType, []), is_(equal_to(True)), )
class BasicTaskEventType(EventType): CREATED = event_info(follows=nothing(), ) ASSIGNED = event_info( follows=all_of("CREATED", but_not("ASSIGNED")), accumulate=union(), requires=["assignee"], ) SCHEDULED = event_info( follows=all_of("CREATED", but_not("SCHEDULED")), accumulate=union(), requires=["deadline"], ) STARTED = event_info(follows=all_of("ASSIGNED", "SCHEDULED"), ) CANCELED = event_info(follows=event("STARTED"), ) COMPLETED = event_info(follows=event("STARTED"), ) ENDED = event_info( follows=event("COMPLETED"), auto_transition=True, )
def __init__(self, follows=None, accumulate=None, restarting=False, requires=(), auto_transition=False): """ :param follows: an instance of the event mini-grammar :param accumulate: whether the event type should accumulating state :param restarting: whether the event type may restart a (new) version :param requires: validate type-specific required fields :param auto_transition: whether this event should be autogenereated when possible """ self.follows = follows if follows is not None else nothing() self.accumulate = accumulate if accumulate is not None else current() self.restarting = restarting self.requires = requires self.auto_transition = auto_transition
class CustomerEventType(EventType): CustomerStartedOrder = event_info(follows=nothing(), requires=["order_id"]) CustomerStartedPizza = event_info(follows=any_of("CustomerStartedOrder", "CustomerFinalizedPizza"), requires=[ "pizza_id", ]) CustomerChosePizzaType = event_info(follows=any_of("CustomerStartedPizza"), requires=[ "pizza_type", "pizza_size", ]) CustomerAddedTopping = event_info(follows=any_of("CustomerChosePizzaType"), requires=[ "topping_type", ]) CustomerFinalizedPizza = event_info(follows=any_of( "CustomerChosePizzaType", "CustomerAddedTopping", ), )
class FlexibleTaskEventType(EventType): # Used to test is_initial CREATED = event_info(follows=any_of( "CREATED", nothing(), ), )
class ActivityEventType(EventType): CREATED = event_info(follows=nothing(), ) CANCELED = event_info(follows=event("CREATED"), )