Пример #1
0
    def test_log_debug(self):
        """
        Log at DEBUG when configured to.

        """
        debug_options = AuditOptions(
            include_request_body=True,
            include_response_body=True,
            include_path=True,
            include_query_string=True,
            log_as_debug=True,
        )

        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(debug_options, test_func, None)

            logger = MagicMock()
            request_info.log(logger)
            logger.debug.assert_called_with(
                dict(
                    operation="test_func",
                    method="GET",
                    func="test_func",
                ))
            logger.info.assert_not_called()
            logger.warning.assert_not_called()
Пример #2
0
    def test_log_path(self):
        with self.graph.flask.test_request_context("/bar"):
            request_info = RequestInfo(self.options, test_func, None)

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(dict(
                operation="test_func",
                method="GET",
                func="test_func",
                foo="bar",
            ))
Пример #3
0
    def test_log_path(self):
        with self.graph.flask.test_request_context("/bar"):
            request_info = RequestInfo(self.options, test_func, None)

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(dict(
                operation="test_func",
                method="GET",
                func="test_func",
                foo="bar",
            ))
Пример #4
0
    def test_log_query_string(self):
        ref_id = str(uuid4())

        with self.graph.flask.test_request_context(
                "/", query_string=dict(foo=ref_id)):
            request_info = RequestInfo(self.options, test_func, None)

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(
                dict(operation="test_func",
                     method="GET",
                     func="test_func",
                     foo=ref_id))
Пример #5
0
    def test_log_response_id_header(self):
        new_id = str(uuid4())
        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(self.options, test_func, None)
            request_info.response_headers = {"X-FooBar-Id": new_id}

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(dict(
                operation="test_func",
                method="GET",
                func="test_func",
                foo_bar_id=new_id,
            ))
Пример #6
0
    def test_log_response_id_header(self):
        new_id = str(uuid4())
        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(self.options, test_func, None)
            request_info.response_headers = {"X-FooBar-Id": new_id}

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(dict(
                operation="test_func",
                method="GET",
                func="test_func",
                foo_bar_id=new_id,
            ))
Пример #7
0
    def test_log_query_string(self):
        ref_id = str(uuid4())

        with self.graph.flask.test_request_context("/", query_string=dict(foo=ref_id)):
            request_info = RequestInfo(self.options, test_func, None)

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(dict(
                operation="test_func",
                method="GET",
                func="test_func",
                foo=ref_id
            ))
Пример #8
0
    def test_log_default(self):
        """
        Log at INFO by default.

        """
        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(self.options, test_func, None)

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(dict(
                operation="test_func",
                method="GET",
                func="test_func",
            ))
            logger.warning.assert_not_called()
Пример #9
0
    def test_log_default(self):
        """
        Log at INFO by default.

        """
        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(self.options, test_func, None)

            logger = MagicMock()
            request_info.log(logger)
            logger.info.assert_called_with(dict(
                operation="test_func",
                method="GET",
                func="test_func",
            ))
            logger.warning.assert_not_called()
Пример #10
0
    def test_log_internal_server_error(self):
        """
        Log at WARNING on internal server error.

        """
        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(self.options, test_func, None)
            request_info.status_code = 500

            logger = MagicMock()
            request_info.log(logger)
            logger.warning.assert_called_with(
                dict(
                    operation="test_func",
                    method="GET",
                    func="test_func",
                ))
            logger.info.assert_not_called()