Beispiel #1
0
    def test_message_received(self, mockmr):
        procmock = Mock()
        procmock.push_context = MagicMock()


        ep = ProcessRPCResponseEndpointUnit(process=procmock, interceptors={})
        ep._routing_obj = procmock

        msg_dict = {'iam':'adict'}
        header_dict =   {'op':'anyop'}
        ep.message_received(msg_dict, header_dict)

        ep._routing_obj.anyop.assert_called_once_with(iam='adict')

        def deny_anyop(self, operation, id=None):
            raise Unauthorized('The anyop operation has been denied')

        msg_dict2 = {'iam':'adict2'}
        ep._routing_obj._service_op_preconditions = {'anyop': 'deny_anyop'}
        ep._routing_obj.container.governance_controller.check_process_operation_preconditions = deny_anyop
        with self.assertRaises(Unauthorized) as cm:
            ep.message_received(msg_dict2, header_dict)
        self.assertIn('The anyop operation has been denied',cm.exception.message)

        #Using the internal mock counter to see if it was still only called once.
        ep._routing_obj.anyop.assert_called_once_with(iam='adict')
Beispiel #2
0
    def test_message_received(self, mockmr):
        procmock = Mock()
        procmock.push_context = MagicMock()

        ep = ProcessRPCResponseEndpointUnit(process=procmock, interceptors={})
        ep._routing_obj = procmock

        msg_dict = {'iam': 'adict'}
        header_dict = {'op': 'anyop'}
        ep.message_received(msg_dict, header_dict)

        ep._routing_obj.anyop.assert_called_once_with(iam='adict')

        def deny_anyop(self, operation, id=None):
            raise Unauthorized('The anyop operation has been denied')

        msg_dict2 = {'iam': 'adict2'}
        ep._routing_obj._service_op_preconditions = {'anyop': 'deny_anyop'}
        ep._routing_obj.container.governance_controller.check_process_operation_preconditions = deny_anyop
        with self.assertRaises(Unauthorized) as cm:
            ep.message_received(msg_dict2, header_dict)
        self.assertIn('The anyop operation has been denied',
                      cm.exception.message)

        #Using the internal mock counter to see if it was still only called once.
        ep._routing_obj.anyop.assert_called_once_with(iam='adict')