Exemplo n.º 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')
Exemplo n.º 2
0
    def test__build_header(self, mockr, mockp):

        mockr.return_value = {'one': 1, 'two': 2}
        mockp.return_value = {'two': -2, 'three': 3}

        ep = ProcessRPCResponseEndpointUnit()
        header = ep._build_header(sentinel.raw_msg)

        self.assertEquals(header, {'one': 1, 'two': -2, 'three': 3})
Exemplo n.º 3
0
    def test__message_received(self, mockmr):
        procmock = Mock()
        procmock.push_context = MagicMock()

        ep = ProcessRPCResponseEndpointUnit(process=procmock)
        ep._message_received(sentinel.msg, sentinel.headers)

        procmock.push_context.assert_called_once_with(sentinel.headers)
        procmock.push_context().__enter__.assert_called_once_with()
        mockmr.assert_called_once_with(ep, sentinel.msg, sentinel.headers)
Exemplo n.º 4
0
    def test_init(self, mockr, mockp):

        ep = ProcessRPCResponseEndpointUnit(process=sentinel.process,
                                            other=sentinel.other)
        mockp.assert_called_once_with(ep, process=sentinel.process)
        mockr.assert_called_once_with(ep, other=sentinel.other)