Example #1
0
    def test_success(self):
        """
        Succeessful responses capture status code.

        """
        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(self.options, test_func, None)
            request_info.capture_response(
                MagicMock(
                    data="{}",
                    status_code=201,
                ))
            dct = request_info.to_dict()
            assert_that(
                dct,
                is_(
                    equal_to(
                        dict(
                            operation="test_func",
                            method="GET",
                            func="test_func",
                            success=True,
                            status_code=201,
                        ))),
            )
Example #2
0
    def test_response_body_with_field_deletion(self):
        """
        Can capture the response body with fields removed

        """
        with self.graph.flask.test_request_context("/"):
            g.hide_response_fields = ["foo"]

            request_info = RequestInfo(self.options, test_func, None)
            request_info.capture_response(
                MagicMock(
                    data='{"foo": "bar", "this": "that"}',
                    status_code=200,
                ))
            dct = request_info.to_dict()
            assert_that(
                dct,
                is_(
                    equal_to(
                        dict(
                            operation="test_func",
                            method="GET",
                            func="test_func",
                            success=True,
                            status_code=200,
                            response_body=dict(this="that"),
                        ))),
            )
Example #3
0
    def test_response_body_with_field_renaming(self):
        """
        Can capture the response body with field renaming

        """
        with self.graph.flask.test_request_context("/"):
            g.show_response_fields = dict(foo="baz")

            request_info = RequestInfo(self.options, test_func, None)
            request_info.capture_response(
                MagicMock(
                    data='{"foo": "bar"}',
                    status_code=200,
                ))
            dct = request_info.to_dict()
            assert_that(
                dct,
                is_(
                    equal_to(
                        dict(
                            operation="test_func",
                            method="GET",
                            func="test_func",
                            success=True,
                            status_code=200,
                            response_body=dict(baz="bar"),
                        ))),
            )
    def test_response_body_with_field_deletion(self):
        """
        Can capture the response body with fields removed

        """
        with self.graph.flask.test_request_context("/"):
            g.hide_response_fields = ["foo"]

            request_info = RequestInfo(self.options, test_func, None)
            request_info.capture_response(MagicMock(
                data='{"foo": "bar", "this": "that"}',
                status_code=200,
            ))
            dct = request_info.to_dict()
            assert_that(
                dct,
                is_(equal_to(dict(
                    operation="test_func",
                    method="GET",
                    func="test_func",

                    success=True,
                    status_code=200,
                    response_body=dict(this="that"),
                ))),
            )
    def test_response_body_with_field_renaming(self):
        """
        Can capture the response body with field renaming

        """
        with self.graph.flask.test_request_context("/"):
            g.show_response_fields = dict(foo="baz")

            request_info = RequestInfo(self.options, test_func, None)
            request_info.capture_response(MagicMock(
                data='{"foo": "bar"}',
                status_code=200,
            ))
            dct = request_info.to_dict()
            assert_that(
                dct,
                is_(equal_to(dict(
                    operation="test_func",
                    method="GET",
                    func="test_func",

                    success=True,
                    status_code=200,
                    response_body=dict(baz="bar"),
                ))),
            )
    def test_success(self):
        """
        Succeessful responses capture status code.

        """
        with self.graph.flask.test_request_context("/"):
            request_info = RequestInfo(self.options, test_func, None)
            request_info.capture_response(MagicMock(
                data="{}",
                status_code=201,
            ))
            dct = request_info.to_dict()
            assert_that(
                dct,
                is_(equal_to(dict(
                    operation="test_func",
                    method="GET",
                    func="test_func",

                    success=True,
                    status_code=201,
                ))),
            )