Example #1
0
    def test_delegate_handle_response_multiple(self, mocker):
        # Include one hook that can't handle responses
        mock_response_handler = mocker.Mock()
        mock_request_auditor = mocker.Mock()

        chain = hooks.TransactionHookChain(
            hooks.RequestAuditor(mock_request_auditor),
            hooks.ResponseHandler(mock_response_handler),
            hooks.ResponseHandler(mock_response_handler),
        )
        chain.handle_response("consumer", {})
        assert mock_response_handler.call_count == 2
        assert mock_request_auditor.call_count == 0
Example #2
0
 def _get_hook_chain(self, contract):
     chain = list(contract.transaction_hooks)
     converter = contract.get_converter(keys.CONVERT_FROM_RESPONSE_BODY,
                                        contract.return_type)
     if converter is not None:
         # Found a converter that can handle the return type.
         chain.append(hooks.ResponseHandler(converter.convert))
     chain.extend(self._hooks)
     return chain
Example #3
0
 def _get_request_hooks(contract):
     chain = list(contract.transaction_hooks)
     if callable(contract.return_type):
         chain.append(hooks_.ResponseHandler(contract.return_type))
     return chain
Example #4
0
 def _get_hook_chain(self, contract):
     chain = list(contract.transaction_hooks)
     if callable(contract.return_type):
         chain.append(hooks_.ResponseHandler(contract.return_type))
     chain.extend(self._hooks)
     return chain
Example #5
0
 def test_handle_response(self, mocker):
     converter = mocker.Mock()
     input_value = "converted"
     converter.return_value = input_value
     rc = hooks.ResponseHandler(converter)
     assert rc.handle_response(None) is input_value