# 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}}('{{paramName}}', {{{example}}}){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}}
    {{/queryParams}}
    headers = { {{#vendorExtensions.x-prefered-produce}}
        'Accept': '{{mediaType}}',{{/vendorExtensions.x-prefered-produce}}{{#vendorExtensions.x-prefered-consume}}
        'Content-Type': '{{mediaType}}',{{/vendorExtensions.x-prefered-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}}}{{#hasMore}},{{/hasMore}}
    {{^hasMore}}
        }
    {{/hasMore}}
    {{/isMultipart}}
    {{/formParams}}
    response = await client.request(
        method='{{httpMethod}}',
        path='{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}={{{example}}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/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}}
