Example #1
0
    def test_empty_no_associated_dispatch_rule(self):
        """
        Test if an UnknowMessageTypeException is raised when using handle
        function on a report that is not associated with a dispatch_rule
        in the handler's route table

        """
        handler = FormulaDispatcherReportHandler(init_state())

        with pytest.raises(UnknowMessageTypeException):
            handler.handle(REPORT_1)
Example #2
0
    def gen_test_get_formula_id(self, primary_dispatch_rule, dispatch_rule,
                                input_report, validation_id, state):
        """instanciate the handler whit given route table and primary dispatch
        rule, test if the handle function application on *input_report* return
        the same reports as in *validation_reports*

        """
        handler = FormulaDispatcherReportHandler(state)

        formula_ids = handler._extract_formula_id(input_report, dispatch_rule,
                                                  primary_dispatch_rule)
        formula_ids.sort()
        validation_id.sort()

        assert formula_ids == validation_id
Example #3
0
    def setup(self):
        """
        Check if there is a primary group by rule. Set define
        StartMessage, PoisonPillMessage and Report handlers
        """
        Actor.setup(self)
        if self.state.route_table.primary_dispatch_rule is None:
            raise NoPrimaryDispatchRuleRuleException()

        self.add_handler(Report, FormulaDispatcherReportHandler())
        self.add_handler(PoisonPillMessage, PoisonPillMessageHandler())
        self.add_handler(StartMessage, StartHandler())
Example #4
0
    def gen_test_handle(self, input_report, init_formula_id_list,
                        formula_id_validation_list, init_state):
        """instanciate the handler whit given route table and primary
        dispatchrule rule, test if the handle function return a state
        containing formula which their id are in formula_id_validation_list

        """
        init_state.route_table.dispatch_rule(Report1, DispatchRule1AB(True))
        init_state.route_table.dispatch_rule(Report2, DispatchRule2AC())
        handler = FormulaDispatcherReportHandler(init_state)

        for formula_id in init_formula_id_list:
            init_state.add_formula(formula_id)

        handler.handle(input_report)
        formula_id_result_list = list(
            map(lambda x: x[0], init_state.get_all_formula()))
        formula_id_result_list.sort(key=lambda result_tuple: result_tuple[0])

        formula_id_result_list.sort()
        formula_id_validation_list.sort()
        assert formula_id_result_list == formula_id_validation_list