def setUp(self): self.a_client = Node() self.the_company = Node() self.a_process = Process(self.the_company, self.a_client) self.a_processing_unit = Node() self.a_movement = Movement(self.a_processing_unit, self.a_processing_unit)
class ProcessSpec(unittest.TestCase): def setUp(self): self.a_client = Node() self.the_company = Node() self.a_process = Process(self.the_company, self.a_client) self.a_processing_unit = Node() self.a_movement = Movement(self.a_processing_unit, self.a_processing_unit) def it_inserts_a_movement(self): #should not work non_movement = "I am not a Movement" (self.a_process.insert_movement, 'Ops!', non_movement) | should | throw(ContractError) #test doubles won't work given type checking rules, using classic self.a_process.insert_movement('A movement', self.a_movement) self.a_process.movements | should | contain('A movement') def it_inserts_a_node(self): #should not work non_node = "I am not a Node" (self.a_process.insert_node, 'Ops!', non_node) | should | throw(ContractError) #test doubles won't work given type checking rules, using classic self.a_process.insert_node('A company processing unit', self.a_processing_unit) self.a_process.nodes | should | contain('A company processing unit')
def then_a_new_loan_request_with_the_account_number_and_desired_value_is_created( step, account_number, desired_value): #Processes are nodes that use the company as the source node, and the client as destination world.the_company = Machine() world.a_client = Person() #now the business process starts to be assembled world.an_individual_credit_operation = Process(world.the_company, world.a_client) world.loan_request_creation = Transformation( world.credit_analyst.decorated, world.credit_analyst.decorated) world.loan_request_creation.set_action( world.credit_analyst.create_loan_request) world.loan_request_creation.action | should | equal_to( world.credit_analyst.create_loan_request) #associates the transformation to the process world.an_individual_credit_operation.insert_movement( 'loan request creation', world.loan_request_creation) world.an_individual_credit_operation.movements | should | contain( 'loan request creation') #finally it runs the transformation... world.an_individual_credit_operation.movements[ 'loan request creation'].perform(world.account, desired_value) #checks if the loan request is stored in the Node's input_area world.credit_analyst.decorated.input_area | should | contain( account_number)
def then_a_new_loan_request_with_the_account_number_and_desired_value_is_created( step, account_number, desired_value): #Processes are nodes that use the company as the source node, and the client as destination world.the_company = Machine() world.a_client = Person() #now the business process starts to be assembled world.an_individual_credit_operation = Process( 'Individual Customer Credit Operation') world.an_individual_credit_operation.set_source(world.the_company) world.an_individual_credit_operation.set_destination(world.a_client) #configures the process using a template state machine template = LoanProcess() configurator = StateMachineConfigurator(template) configurator.configure(world.an_individual_credit_operation) #configures the loan request creation the_movement = world.an_individual_credit_operation.configure_activity_logger( world.credit_analyst.decorated, world.credit_analyst.decorated, world.an_individual_credit_operation.create_loan_request, CreditAnalystDecorator.create_loan_request) world.an_individual_credit_operation.movements | should | contain( the_movement.activity.__name__) #runs the loan request creation the_movement.context = world.an_individual_credit_operation.run_activity( the_movement, world.credit_analyst, world.account, desired_value) world.an_individual_credit_operation.current_state() | should | equal_to( 'request_created')
class ProcessSpec(unittest.TestCase): def setUp(self): self.a_client = Node() self.the_company = Node() self.a_process = Process(self.the_company, self.a_client) self.a_processing_unit = Node() self.a_movement = Movement(self.a_processing_unit, self.a_processing_unit) def it_inserts_a_movement(self): # should not work non_movement = "I am not a Movement" (self.a_process.insert_movement, "Ops!", non_movement) | should | throw(ContractError) # test doubles won't work given type checking rules, using classic self.a_process.insert_movement("A movement", self.a_movement) self.a_process.movements | should | contain("A movement") def it_inserts_a_node(self): # should not work non_node = "I am not a Node" (self.a_process.insert_node, "Ops!", non_node) | should | throw(ContractError) # test doubles won't work given type checking rules, using classic self.a_process.insert_node("A company processing unit", self.a_processing_unit) self.a_process.nodes | should | contain("A company processing unit")
def and_there_is_a_refused_loan_request_of_value_value_for_account_account_number(step, desired_value, account_number): #preparing the context #puts the process in the refusal path world.an_individual_credit_operation = Process('Individual Customer Credit Operation') template = LoanProcess() configurator = StateMachineConfigurator(template) configurator.configure(world.an_individual_credit_operation) world.an_individual_credit_operation.create_loan_request() world.an_individual_credit_operation.analyst_select_request() #directly creating a loan request world.credit_analyst.create_loan_request(world.account, int(desired_value)) #forces the loan request approval and its transfer to the output_area world.credit_analyst.decorated.input_area[world.account.number].approved = False world.credit_analyst.decorated.transfer(world.account.number, 'input', 'output') world.credit_analyst.decorated.output_area |should| contain(world.account.number)
def setUp(self): self.process = Process() template = LoanProcess() configurator = StateMachineConfigurator(template) configurator.configure(self.process)
class FluidityProcessSpec(unittest.TestCase): def setUp(self): self.process = Process() template = LoanProcess() configurator = StateMachineConfigurator(template) configurator.configure(self.process) def it_makes_the_process_respond_to_the_example_state_machine_events(self): self.process | should | respond_to('create_loan_request') self.process | should | respond_to('analyst_select_request') self.process | should | respond_to('loan_refused') self.process | should | respond_to('loan_accepted') self.process | should | respond_to('time_to_transfer_value') def it_runs_the_example_refusal_path(self): self.process.create_loan_request() self.process.current_state() | should | equal_to('request_created') self.process.loan_refused | should | throw(InvalidTransition) self.process.analyst_select_request() self.process.current_state() | should | equal_to('request_analyzed') #loan refused self.process.loan_refused() self.process.current_state() | should | equal_to('refusal_letter_sent') def it_runs_the_example_acceptance_path(self): #process was restarted by setUp() self.process.create_loan_request() self.process.current_state() | should | equal_to('request_created') self.process.loan_refused | should | throw(InvalidTransition) self.process.analyst_select_request() self.process.current_state() | should | equal_to('request_analyzed') #loan accepted self.process.loan_accepted() self.process.current_state() | should | equal_to('loan_created') self.process.time_to_transfer_value() self.process.current_state() | should | equal_to('value_transfered') def it_configures_and_runs_a_process(self): self.a_node = Node() self.another_node = Node() self.a_decorator = FakeDecorator() #process was restarted by setUp() the_movement = self.process.configure_activity_logger( self.a_node, self.another_node, self.process.create_loan_request, FakeDecorator.do_something) #starts running the_movement.context = self.process.run_activity( the_movement, self.a_decorator, 10) the_movement.context['result'] | should | equal_to( "this is an operation's return value:10") self.process.current_state() | should | equal_to('request_created') #configures and runs the template's refusal path #should go wrong the_movement = self.process.configure_activity_logger( self.a_node, self.another_node, self.process.loan_refused, FakeDecorator.do_something) (self.process.run_activity, the_movement, self.a_decorator, 10) | should | throw(InvalidTransition) #now doing the right thing the_movement = self.process.configure_activity_logger( self.a_node, self.another_node, self.process.analyst_select_request, FakeDecorator.do_something) the_movement.context = self.process.run_activity( the_movement, self.a_decorator, 10) self.process.current_state() | should | equal_to('request_analyzed') the_movement = self.process.configure_activity_logger( self.a_node, self.another_node, self.process.loan_refused, FakeDecorator.do_something) the_movement.context = self.process.run_activity( the_movement, self.a_decorator, 15) self.process.current_state() | should | equal_to('refusal_letter_sent')
class FluidityProcessSpec(unittest.TestCase): def setUp(self): self.process = Process() template = LoanProcess() configurator = StateMachineConfigurator(template) configurator.configure(self.process) def it_makes_the_process_respond_to_the_example_state_machine_events(self): self.process |should| respond_to('create_loan_request') self.process |should| respond_to('analyst_select_request') self.process |should| respond_to('loan_refused') self.process |should| respond_to('loan_accepted') self.process |should| respond_to('time_to_transfer_value') def it_runs_the_example_refusal_path(self): self.process.create_loan_request() self.process.current_state() |should| equal_to('request_created') self.process.loan_refused |should| throw(InvalidTransition) self.process.analyst_select_request() self.process.current_state() |should| equal_to('request_analyzed') #loan refused self.process.loan_refused() self.process.current_state() |should| equal_to('refusal_letter_sent') def it_runs_the_example_acceptance_path(self): #process was restarted by setUp() self.process.create_loan_request() self.process.current_state() |should| equal_to('request_created') self.process.loan_refused |should| throw(InvalidTransition) self.process.analyst_select_request() self.process.current_state() |should| equal_to('request_analyzed') #loan accepted self.process.loan_accepted() self.process.current_state() |should| equal_to('loan_created') self.process.time_to_transfer_value() self.process.current_state() |should| equal_to('value_transfered') def it_configures_and_runs_a_process(self): self.a_node = Node() self.another_node = Node() self.a_decorator = FakeDecorator() #process was restarted by setUp() the_movement = self.process.configure_activity_logger(self.a_node, self.another_node, self.process.create_loan_request, FakeDecorator.do_something) #starts running the_movement.context = self.process.run_activity(the_movement, self.a_decorator, 10) the_movement.context['result'] |should| equal_to("this is an operation's return value:10") self.process.current_state() |should| equal_to('request_created') #configures and runs the template's refusal path #should go wrong the_movement = self.process.configure_activity_logger(self.a_node, self.another_node, self.process.loan_refused, FakeDecorator.do_something) (self.process.run_activity, the_movement, self.a_decorator, 10) |should| throw(InvalidTransition) #now doing the right thing the_movement = self.process.configure_activity_logger(self.a_node, self.another_node, self.process.analyst_select_request, FakeDecorator.do_something) the_movement.context = self.process.run_activity(the_movement, self.a_decorator,10) self.process.current_state() |should| equal_to('request_analyzed') the_movement = self.process.configure_activity_logger(self.a_node, self.another_node, self.process.loan_refused, FakeDecorator.do_something) the_movement.context = self.process.run_activity(the_movement, self.a_decorator,15) self.process.current_state() |should| equal_to('refusal_letter_sent')
def it_inserts_a_subprocess(self): a_subprocess = Process() self.a_process.insert_movement('A subprocess', a_subprocess)
def setUp(self): self.a_client = Node() self.the_company = Node() self.a_process = Process() self.a_process.set_source(self.the_company) self.a_process.set_destination(self.a_client)
class ProcessSpec(unittest.TestCase): def setUp(self): self.a_client = Node() self.the_company = Node() self.a_process = Process() self.a_process.set_source(self.the_company) self.a_process.set_destination(self.a_client) def it_inserts_a_movement(self): #should not work non_movement = "I am not a Movement" (self.a_process.insert_movement, 'Ops!',non_movement) |should| throw(AssociationError) #test doubles won't work given type checking rules a_movement = Movement() self.a_process.insert_movement('A movement', a_movement) self.a_process.movements |should| contain('A movement') def it_inserts_a_subprocess(self): a_subprocess = Process() self.a_process.insert_movement('A subprocess', a_subprocess) def an_activity(self): ''' Represents an activity of a workflow engine. A business decorator's method will be attributed to this activity, making the activity a proxy to the decorator's method. ''' pass def it_configures_a_movement_as_an_activity_logger(self): logger = self.a_process.configure_activity_logger(self.the_company, self.a_client, self.an_activity, FakeDecorator.do_something) logger.source |should| be(self.the_company) logger.destination |should| be(self.a_client) logger.activity |should| equal_to(self.an_activity) logger.activity_associated_method |should| equal_to(FakeDecorator.do_something) self.a_process.movements |should| include(self.an_activity.__name__) def it_runs_an_activity_through_a_preconfigured_activity_logger(self): logger = self.a_process.configure_activity_logger(self.the_company, self.a_client, self.an_activity, FakeDecorator.do_something) a_decorator = FakeDecorator() logger.context = self.a_process.run_activity(logger, a_decorator, 100, 200) logger.context['actor'] |should| be(a_decorator) logger.context['arguments'] |should| equal_to([100,200]) logger.context['result'] |should| equal_to(300)