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

python-aiohttp.controller_test.mustache Maven / Gradle / Ivy

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

import pytest
import json
from aiohttp import web
{{#operations}}
{{#operation}}
{{#isMultipart}}
from aiohttp import FormData
{{/isMultipart}}
{{/operation}}
{{/operations}}

{{#imports}}{{import}}
{{/imports}}

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

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

    {{{summary}}}
    """
    {{#bodyParam}}
    {{paramName}} = {{{example}}}
    {{/bodyParam}}
    {{#queryParams}}
    {{#-first}}params = [{{/-first}}{{^-first}}                {{/-first}}('{{^vendorExtensions.x-python-connexion-openapi-name}}{{paramName}}{{/vendorExtensions.x-python-connexion-openapi-name}}{{#vendorExtensions.x-python-connexion-openapi-name}}{{vendorExtensions.x-python-connexion-openapi-name}}{{/vendorExtensions.x-python-connexion-openapi-name}}', {{{example}}}){{^-last}},{{/-last}}{{#-last}}]{{/-last}}
    {{/queryParams}}
    headers = { {{#vendorExtensions.x-preferred-produce}}
        'Accept': '{{mediaType}}',{{/vendorExtensions.x-preferred-produce}}{{#vendorExtensions.x-preferred-consume}}
        'Content-Type': '{{mediaType}}',{{/vendorExtensions.x-preferred-consume}}{{#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}}
    {{#isMultipart}}
    {{#-first}}
    data = FormData()
    {{/-first}}
    data.add_field('{{paramName}}', {{{example}}})
    {{/isMultipart}}
    {{^isMultipart}}
    {{#-first}}
    data = {
    {{/-first}}
        '{{paramName}}': {{{example}}}{{^-last}},{{/-last}}
    {{#-last}}
        }
    {{/-last}}
    {{/isMultipart}}
    {{/formParams}}
    response = await client.request(
        method='{{httpMethod}}',
        path='{{{contextPath}}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}={{{example}}}{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/pathParams}},
        headers=headers,{{#bodyParam}}
        json={{paramName}},{{/bodyParam}}{{#formParams}}{{#-first}}
        data=data,{{/-first}}{{/formParams}}{{#queryParams}}{{#-first}}
        params=params,{{/-first}}{{/queryParams}}
        )
    assert response.status == 200, 'Response body is : ' + (await response.read()).decode('utf-8')

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy