def test_init_with_config(self):
     """Configured LoggingInterceptor should call logging.dictConfig.
     """
     config = {'test': True}
     with mock.patch('logging.config.dictConfig') as mock_dictConfig:
         Client.LoggingInterceptor(config)
         mock_dictConfig.assert_called_once_with(config)
Beispiel #2
0
    def _create_test_interceptor(self, config=_MOCK_CONFIG,
                                 endpoint=_MOCK_ENDPOINT):
        """Creates a LoggingInterceptor instance.

        Accepts parameters that are used to override defaults when needed
        for testing.

        Returns:
            A LoggingInterceptor instance.

        Args:
            config: A dict configuration
            endpoint: A str representing an endpoint
        """
        return Client.LoggingInterceptor(config, endpoint)
    def test_intercept_unary_unary_unconfigured(self):
        """No _logger methods should be called.

        When intercepting requests, no logging methods should be called if
        LoggingInterceptor was initialized without a configuration.
        """
        mock_client_call_details = self._get_mock_client_call_details()
        mock_continuation_fn = self._get_mock_continuation_fn()
        mock_request = self._get_mock_request()
        # Since logging configuration is global it needs to be reset here
        # so that state from previous tests does not affect these assertions
        logging.disable(logging.CRITICAL)
        logger_spy = mock.Mock(wraps=Client._logger)
        interceptor = Client.LoggingInterceptor()
        interceptor.intercept_unary_unary(mock_continuation_fn,
                                          mock_client_call_details,
                                          mock_request)

        logger_spy.debug.assert_not_called()
        logger_spy.info.assert_not_called()
        logger_spy.warning.assert_not_called()
 def test_init_no_config(self):
     """Unconfigured LoggingInterceptor should not call logging.dictConfig.
     """
     with mock.patch('logging.config.dictConfig') as mock_dictConfig:
         Client.LoggingInterceptor()
         mock_dictConfig.assert_not_called()