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})
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})
def send(self, msg, headers=None, **kwargs): c = self.participant.get_conversation_endpoint(headers['conv-id']) if c: c.send(self.conv_type.client_role, msg, headers, **kwargs) self.participant.end_conversation_endpoint(c) else: #Try to be backward compatiable with non conversation endpoints ProcessRPCResponseEndpointUnit.send(self, msg, headers, **kwargs)
def send(self, msg, headers=None, **kwargs): c = self.participant.get_conversation_endpoint(headers["conv-id"]) if c: c.send(self.conv_type.client_role, msg, headers, **kwargs) self.participant.end_conversation_endpoint(c) else: # Try to be backward compatiable with non conversation endpoints ProcessRPCResponseEndpointUnit.send(self, msg, headers, **kwargs)
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)
def test__message_received(self, mockmr): procmock = Mock() procmock.push_context = MagicMock() ep = ProcessRPCResponseEndpointUnit(process=procmock, interceptors={}) 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)
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')
def message_received(self, msg, headers): # Try to be backward compatiable with non conversation endpoints if "conv-msg-type" in headers: self.participant.receive_invitation(msg, headers) # TODO = reject an invitation is not supported yet self.participant.accept_next_invitation(self, merge_with_first_send=True) result, response_headers = ProcessRPCResponseEndpointUnit.message_received(self, msg, headers) return result, response_headers
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')
def message_received(self, msg, headers): #Try to be backward compatiable with non conversation endpoints if 'conv-msg-type' in headers: self.participant.receive_invitation(msg, headers) #TODO = reject an invitation is not supported yet self.participant.accept_next_invitation(self, merge_with_first_send=True) result, response_headers = ProcessRPCResponseEndpointUnit.message_received( self, msg, headers) return result, response_headers
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)
def _message_send(self, msg, headers=None, **kwargs): return ProcessRPCResponseEndpointUnit.send(self, msg, headers, **kwargs)
def __init__(self, **kwargs): ProcessRPCResponseEndpointUnit.__init__(self, **kwargs)