<s> """<STR_LIT>""" <EOL> import datetime <EOL> import functools <EOL> from jsonschema . exceptions import ValidationError <EOL> import pytest <EOL> from bravado . client import SwaggerClient <EOL> from bravado . compat import json <EOL> from bravado . exception import HTTPError <EOL> from tests . functional . conftest import register_spec , register_get , API_DOCS_URL <EOL> register_test_http = functools . partial ( <EOL> register_get , <EOL> '<STR_LIT>' ) <EOL> def assert_result ( expected_result ) : <EOL> resource = SwaggerClient . from_url ( API_DOCS_URL ) . api_test <EOL> assert expected_result == resource . testHTTP ( test_param = '<STR_LIT:foo>' ) . result ( ) <EOL> def assert_raises_and_matches ( exc_type , match_str ) : <EOL> resource = SwaggerClient . from_url ( API_DOCS_URL ) . api_test <EOL> with pytest . raises ( exc_type ) as excinfo : <EOL> resource . testHTTP ( test_param = '<STR_LIT:foo>' ) . result ( ) <EOL> assert match_str in str ( excinfo . value ) <EOL> def test_500_error_raises_HTTPError ( httprettified , swagger_dict ) : <EOL> register_spec ( swagger_dict ) <EOL> register_get ( '<STR_LIT>' , status = <NUM_LIT> ) <EOL> assert_raises_and_matches ( HTTPError , '<STR_LIT>' ) <EOL> def test_primitive_types_returned_in_response ( httprettified , swagger_dict ) : <EOL> rtypes = { <EOL> '<STR_LIT:string>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : True <EOL> } <EOL> for rtype , rvalue in rtypes . items ( ) : <EOL> register_spec ( swagger_dict , { '<STR_LIT:type>' : rtype } ) <EOL> register_test_http ( body = json . dumps ( rvalue ) ) <EOL> assert_result ( rvalue ) <EOL> def test_invalid_primitive_types_in_response_raises_ValidationError ( <EOL> httprettified , swagger_dict ) : <EOL> rtypes = { <EOL> '<STR_LIT:string>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> for rtype , rvalue in rtypes . items ( ) : <EOL> register_spec ( swagger_dict , { '<STR_LIT:type>' : rtype } ) <EOL> register_test_http ( body = json . dumps ( rvalue ) ) <EOL> assert_raises_and_matches ( ValidationError , '<STR_LIT>' ) <EOL> def test_unstructured_json_in_response ( httprettified , swagger_dict ) : <EOL> response_spec = { '<STR_LIT:type>' : '<STR_LIT:object>' , '<STR_LIT>' : True } <EOL> register_spec ( swagger_dict , response_spec ) <EOL> register_test_http ( body = '<STR_LIT>' ) <EOL> assert_result ( { '<STR_LIT>' : '<STR_LIT:bar>' } ) <EOL> def test_date_format_in_reponse ( httprettified , swagger_dict ) : <EOL> response_spec = { '<STR_LIT:type>' : '<STR_LIT:string>' , '<STR_LIT>' : '<STR_LIT:date>' } <EOL> register_spec ( swagger_dict , response_spec ) <EOL> register_test_http ( body = json . dumps ( "<STR_LIT>" ) ) <EOL> assert_result ( datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:10> ) ) <EOL> def test_array_in_response ( httprettified , swagger_dict ) : <EOL> response_spec = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> } , <EOL> } <EOL> register_spec ( swagger_dict , response_spec ) <EOL> expected_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> register_test_http ( body = json . dumps ( expected_array ) ) <EOL> assert_result ( expected_array ) </s>
