| 1 | # coding: utf-8
|
|---|
| 2 |
|
|---|
| 3 | import pytest
|
|---|
| 4 | import json
|
|---|
| 5 |
|
|---|
| 6 | {{#imports}}{{import}} # noqa: E501
|
|---|
| 7 | {{/imports}}
|
|---|
| 8 |
|
|---|
| 9 | # {{classFilename}} integration test stubs
|
|---|
| 10 | {{#operations}}
|
|---|
| 11 | {{#operation}}
|
|---|
| 12 | {{#vendorExtensions.x-skip-test}}
|
|---|
| 13 | @pytest.mark.skip(reason="{{reason}}")
|
|---|
| 14 | {{/vendorExtensions.x-skip-test}}
|
|---|
| 15 | {{#vendorExtensions.x-xfail-test}}
|
|---|
| 16 | @pytest.mark.xfail(reason=('Reason: '
|
|---|
| 17 | '{{reason}}')) # noqa: E501
|
|---|
| 18 | {{/vendorExtensions.x-xfail-test}}
|
|---|
| 19 | def test_{{operationId}}({{#vendorExtensions.x-mapservice-required}}mapservice, {{/vendorExtensions.x-mapservice-required}}client):
|
|---|
| 20 | """Test case for {{{operationId}}}
|
|---|
| 21 | {{{summary}}}
|
|---|
| 22 | """
|
|---|
| 23 | {{#bodyParam}}
|
|---|
| 24 | {{paramName}} = {{{example}}}
|
|---|
| 25 | {{/bodyParam}}
|
|---|
| 26 | {{#queryParams}}
|
|---|
| 27 | {{#-first}}query_string = [{{/-first}}{{^-first}} {{/-first}}('{{paramName}}', '{{{example}}}'){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}}
|
|---|
| 28 | {{/queryParams}}
|
|---|
| 29 | headers = { {{#vendorExtensions.x-prefered-produce}}
|
|---|
| 30 | 'Accept': '{{mediaType}}',{{/vendorExtensions.x-prefered-produce}}{{#vendorExtensions.x-prefered-consume}}
|
|---|
| 31 | 'Content-Type': '{{mediaType}}',{{/vendorExtensions.x-prefered-consume}}{{#headerParams}}
|
|---|
| 32 | '{{paramName}}': '{{{example}}}',{{/headerParams}}{{#authMethods}}
|
|---|
| 33 | {{#isBasicBasic}}'Authorization': 'Basic YXV0b3Rlc3RzOmF1dG90ZXN0cw==',{{/isBasicBasic}}
|
|---|
| 34 | {{/authMethods}}
|
|---|
| 35 | }
|
|---|
| 36 | {{#formParams}}
|
|---|
| 37 | {{#-first}}data = dict({{/-first}}{{^-first}} {{/-first}}{{paramName}}={{{example}}}{{#hasMore}},{{/hasMore}}{{#-last}}){{/-last}}
|
|---|
| 38 | {{/formParams}}
|
|---|
| 39 |
|
|---|
| 40 | {{#responses}}
|
|---|
| 41 | {{#-first}}
|
|---|
| 42 | response = client.open(
|
|---|
| 43 | '{{#contextPath}}{{{.}}}{{/contextPath}}{{{path}}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}='{{{example}}}'{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}},
|
|---|
| 44 | method='{{httpMethod}}',
|
|---|
| 45 | headers=headers{{#bodyParam}},
|
|---|
| 46 | data=json.dumps({{paramName}}){{^consumes}},
|
|---|
| 47 | content_type='application/json'{{/consumes}}{{/bodyParam}}{{#formParams}}{{#-first}},
|
|---|
| 48 | data=data{{/-first}}{{/formParams}}{{#consumes}}{{#-first}},
|
|---|
| 49 | content_type='{{{mediaType}}}'{{/-first}}{{/consumes}}{{#queryParams}}{{#-first}},
|
|---|
| 50 | query_string=query_string{{/-first}}{{/queryParams}})
|
|---|
| 51 | try:
|
|---|
| 52 | response_data = response.data.decode('utf-8')
|
|---|
| 53 | except Exception as e:
|
|---|
| 54 | response_data = 'Failed to decode body with {}'.format(repr(e))
|
|---|
| 55 | assert response.status_code == {{code}}, \
|
|---|
| 56 | 'Response body is : {}'.format(response_data)
|
|---|
| 57 | {{/-first}}
|
|---|
| 58 | {{^-first}}
|
|---|
| 59 | # Skipping responses with status code {{code}}
|
|---|
| 60 | {{/-first}}
|
|---|
| 61 | {{/responses}}
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | {{/operation}}
|
|---|
| 65 | {{/operations}}
|
|---|