Exemple #1
0
    def test_swagger(self):
        """
        Swagger definitions including this operation.

        """
        response = self.client.get("/api/v1/swagger",
                                   query_string=dict(validate_schema=True))
        assert_that(response.status_code, is_(equal_to(200)))
        swagger = loads(response.get_data().decode("utf-8"))
        assert_that(
            swagger["paths"],
            is_(
                equal_to({
                    "/foo/get": {
                        "get": {
                            "tags": ["foo"],
                            "responses": {
                                "default": {
                                    "description": "An error occurred",
                                    "schema": {
                                        "$ref": "#/definitions/Error",
                                    }
                                },
                                "200": {
                                    "description": "My doc string",
                                    "schema": {
                                        "$ref": "#/definitions/QueryResult",
                                    }
                                }
                            },
                            "parameters": [
                                {
                                    "in": "header",
                                    "name": "X-Response-Skip-Null",
                                    "required": False,
                                    "type": "string",
                                },
                                {
                                    "required": False,
                                    "type": "string",
                                    "name": "optional_value",
                                    "in": "query",
                                },
                                {
                                    "required": True,
                                    "type": "string",
                                    "name": "required_value",
                                    "in": "query",
                                },
                            ],
                            "operationId":
                            "query",
                        }
                    }
                })))
    def test_swagger(self):
        """
        Swagger definitions including this operation.

        """
        response = self.client.get("/api/v1/swagger")
        assert_that(response.status_code, is_(equal_to(200)))
        swagger = loads(response.get_data().decode("utf-8"))
        assert_that(
            swagger["paths"],
            is_(
                equal_to({
                    "/foo/do": {
                        "post": {
                            "tags": ["foo"],
                            "responses": {
                                "default": {
                                    "description": "An error occurred",
                                    "schema": {
                                        "$ref": "#/definitions/Error",
                                    }
                                },
                                "200": {
                                    "description": "My doc string",
                                    "schema": {
                                        "$ref": "#/definitions/CommandResult",
                                    }
                                }
                            },
                            "parameters": [
                                {
                                    "in": "header",
                                    "name": "X-Response-Skip-Null",
                                    "required": False,
                                    "type": "string",
                                },
                                {
                                    "schema": {
                                        "$ref":
                                        "#/definitions/CommandArgument",
                                    },
                                    "name": "body",
                                    "in": "body",
                                },
                            ],
                            "operationId":
                            "command",
                        }
                    }
                })))
Exemple #3
0
    def test_query(self):
        """
        The query can take advantage of boilerplate encoding/decoding.

        """
        uri = "/api/v1/foo/get"
        query_string = {
            "value": "bar",
        }
        response = self.client.get(uri, query_string=query_string)
        assert_that(response.status_code, is_(equal_to(200)))
        assert_that(loads(response.get_data().decode("utf-8")), is_(equal_to({
            "result": True,
            "value": "bar",
        })))
    def test_command(self):
        """
        The command can take advantage of boilerplate encoding/decoding.

        """
        uri = "/api/v1/foo/do"
        request_data = {
            "value": "bar",
        }
        response = self.client.post(uri, data=dumps(request_data))
        assert_that(response.status_code, is_(equal_to(200)))
        assert_that(loads(response.get_data().decode("utf-8")), is_(equal_to({
            "result": True,
            "value": "bar",
        })))
    def test_command(self):
        """
        The command can take advantage of boilerplate encoding/decoding.

        """
        uri = "/api/v1/foo/do"
        request_data = {
            "value": "bar",
        }
        response = self.client.post(uri, data=dumps(request_data))
        assert_that(response.status_code, is_(equal_to(200)))
        assert_that(loads(response.get_data().decode("utf-8")), is_(equal_to({
            "result": True,
            "value": "bar",
        })))
    def test_query(self):
        """
        The query can take advantage of boilerplate encoding/decoding.

        """
        uri = "/api/v1/foo/get"
        query_string = {
            "value": "bar",
        }
        response = self.client.get(uri, query_string=query_string)
        assert_that(response.status_code, is_(equal_to(200)))
        assert_that(loads(response.get_data().decode("utf-8")), is_(equal_to({
            "result": True,
            "value": "bar",
        })))
    def test_swagger(self):
        """
        Swagger definitions including this operation.

        """
        response = self.client.get("/api/v1/swagger")
        assert_that(response.status_code, is_(equal_to(200)))
        swagger = loads(response.get_data().decode("utf-8"))
        assert_that(swagger["paths"], is_(equal_to({
            "/foo/do": {
                "post": {
                    "tags": ["foo"],
                    "responses": {
                        "default": {
                            "description": "An error occurred", "schema": {
                                "$ref": "#/definitions/Error",
                            }
                        },
                        "200": {
                            "description": "My doc string",
                            "schema": {
                                "$ref": "#/definitions/CommandResult",
                            }
                        }
                    },
                    "parameters": [
                        {
                            "in": "header",
                            "name": "X-Response-Skip-Null",
                            "required": False,
                            "type": "string",
                        },
                        {
                            "schema": {
                                "$ref": "#/definitions/CommandArgument",
                            },
                            "name": "body",
                            "in": "body",
                        },
                    ],
                    "operationId": "command",
                }
            }
        })))