All Downloads are FREE. Search and download functionalities are using the official Maven repository.

python-fastapi.api_test.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
# coding: utf-8

from fastapi.testclient import TestClient

{{#vendorExtensions.x-skip-test}}
import pytest
{{/vendorExtensions.x-skip-test}}

{{#imports}}{{import}}  # noqa: F401
{{/imports}}

{{#operations}}
{{#operation}}

{{#vendorExtensions.x-skip-test}}
@pytest.mark.skip("{{reason}}")
{{/vendorExtensions.x-skip-test}}
def test_{{operationId}}(client: TestClient):
    """Test case for {{{operationId}}}

    {{{summary}}}
    """
    {{#bodyParam}}
    {{paramName}} = {{#isContainer}}[{{/isContainer}}{{{example}}}{{#isContainer}}]{{/isContainer}}
    {{/bodyParam}}
    {{#queryParams}}
    {{#-first}}params = [{{/-first}}("{{paramName}}", {{{example}}}){{^-last}}, {{/-last}}{{#-last}}]{{/-last}}{{/queryParams}}
    headers = {{=<% %>=}}{<%#headerParams%><%={{ }}=%>
        "{{paramName}}": {{{example}}},{{/headerParams}}{{#authMethods}}
        {{#isOAuth}}"Authorization": "Bearer special-key",{{/isOAuth}}{{#isApiKey}}"{{name}}": "special-key",{{/isApiKey}}{{#isBasicBasic}}"Authorization": "BasicZm9vOmJhcg==",{{/isBasicBasic}}{{#isBasicBearer}}"Authorization": "Bearer special-key",{{/isBasicBearer}}{{/authMethods}}
    }
    {{#formParams}}
    {{#-first}}
    data = {
    {{/-first}}
        "{{paramName}}": {{{example}}}{{^-last}},{{/-last}}
    {{#-last}}
    }
    {{/-last}}
    {{/formParams}}
    response = client.request(
        "{{httpMethod}}",
        "{{{path}}}"{{#pathParams}}{{#-first}}.format({{/-first}}{{baseName}}={{{example}}}{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/pathParams}},
        headers=headers,{{#bodyParam}}
        json={{paramName}},{{/bodyParam}}{{#formParams}}{{#-first}}
        data=data,{{/-first}}{{/formParams}}{{#queryParams}}{{#-first}}
        params=params,{{/-first}}{{/queryParams}}
    )

    # uncomment below to assert the status code of the HTTP response
    #assert response.status_code == 200

{{/operation}}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy