<s> from __future__ import absolute_import <EOL> from pyswagger import SwaggerApp <EOL> from pyswagger . contrib . client . requests import Client <EOL> from ... utils import get_test_data_folder <EOL> from ... . primitives import Model , Array <EOL> import unittest <EOL> import httpretty <EOL> import json <EOL> import six <EOL> app = SwaggerApp . _create_ ( get_test_data_folder ( version = '<STR_LIT>' , which = '<STR_LIT>' ) ) <EOL> client = Client ( ) <EOL> pet_Tom = dict ( id = <NUM_LIT:1> , name = '<STR_LIT>' , tags = [ dict ( id = <NUM_LIT:0> , name = '<STR_LIT>' ) , dict ( id = <NUM_LIT:1> , name = '<STR_LIT>' ) ] ) <EOL> pet_Qoo = dict ( id = <NUM_LIT:2> , name = '<STR_LIT>' , tags = [ dict ( id = <NUM_LIT:0> , name = '<STR_LIT>' ) ] ) <EOL> pet_Sue = dict ( id = <NUM_LIT:3> , name = '<STR_LIT>' , tags = [ dict ( id = <NUM_LIT:0> , name = '<STR_LIT>' ) ] ) <EOL> pet_Kay = dict ( id = <NUM_LIT:4> , name = '<STR_LIT>' , category = dict ( id = <NUM_LIT:2> , name = '<STR_LIT>' ) , status = '<STR_LIT>' , photoUrls = None , tags = None ) <EOL> pet_QQQ = dict ( id = <NUM_LIT:1> , name = '<STR_LIT>' , category = dict ( id = <NUM_LIT:1> , name = '<STR_LIT>' ) , tags = None , status = None ) <EOL> @ httpretty . activate <EOL> class RequestsClient_Pet_TestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_updatePet ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( <EOL> httpretty . PUT , <EOL> '<STR_LIT>' , <EOL> status = <NUM_LIT:200> <EOL> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( body = pet_QQQ ) ) <EOL> self . assertEqual ( httpretty . last_request ( ) . method , '<STR_LIT>' ) <EOL> self . assertEqual ( httpretty . last_request ( ) . headers [ '<STR_LIT>' ] , '<STR_LIT:application/json>' ) <EOL> self . assertTrue ( json . loads ( httpretty . last_request ( ) . body . decode ( '<STR_LIT:utf-8>' ) ) , pet_QQQ ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . data , None ) <EOL> self . assertEqual ( resp . header [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> def test_findPetsByStatus ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . GET , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = json . dumps ( [ pet_Tom ] ) <EOL> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( status = [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( httpretty . last_request ( ) . querystring , dict ( status = [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertTrue ( isinstance ( resp . data , Array ) ) <EOL> self . assertTrue ( len ( resp . data ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( isinstance ( resp . data [ <NUM_LIT:0> ] , Model ) ) <EOL> self . assertEqual ( resp . data [ <NUM_LIT:0> ] . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . data [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( resp . data [ <NUM_LIT:0> ] . tags , Array ) ) <EOL> def test_findPetsByTags ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . GET , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = json . dumps ( [ pet_Tom , pet_Qoo ] ) <EOL> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( tags = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( httpretty . last_request ( ) . querystring , dict ( tags = [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertTrue ( isinstance ( resp . data , Array ) ) <EOL> self . assertTrue ( len ( resp . data ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( isinstance ( resp . data [ <NUM_LIT:0> ] , Model ) ) <EOL> self . assertEqual ( resp . data [ <NUM_LIT:1> ] . id , <NUM_LIT:2> ) <EOL> self . assertEqual ( resp . data [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( resp . data [ <NUM_LIT:1> ] . tags , Array ) ) <EOL> def test_partialUpdate ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . PATCH , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = json . dumps ( [ pet_Tom , pet_Sue ] ) <EOL> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( <EOL> petId = <NUM_LIT:0> , <EOL> body = pet_Tom <EOL> ) ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertTrue ( isinstance ( resp . data , Array ) ) <EOL> self . assertEqual ( resp . data [ <NUM_LIT:1> ] . id , <NUM_LIT:3> ) <EOL> self . assertEqual ( resp . data [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( resp . data [ <NUM_LIT:1> ] . tags , Array ) ) <EOL> def test_updatePetWithForm ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . POST , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( petId = <NUM_LIT:0> , name = '<STR_LIT>' , status = '<STR_LIT>' ) ) <EOL> self . assertEqual ( httpretty . last_request ( ) . parsed_body , { u'<STR_LIT:status>' : [ u'<STR_LIT>' ] , u'<STR_LIT:name>' : [ u'<STR_LIT>' ] } ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . data , None ) <EOL> def test_addPet ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . POST , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( body = pet_Kay ) ) <EOL> self . assertEqual ( httpretty . last_request ( ) . parsed_body , pet_Kay ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . data , None ) <EOL> def test_deletePet ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . DELETE , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( petId = <NUM_LIT> ) ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . data , None ) <EOL> def test_getPetById ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . GET , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = json . dumps ( pet_Tom ) <EOL> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( petId = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertTrue ( isinstance ( resp . data , Model ) ) <EOL> self . assertEqual ( resp . data , <EOL> { u'<STR_LIT:name>' : '<STR_LIT>' , u'<STR_LIT>' : [ { u'<STR_LIT:id>' : <NUM_LIT:0> , u'<STR_LIT:name>' : '<STR_LIT>' } , { u'<STR_LIT:id>' : <NUM_LIT:1> , u'<STR_LIT:name>' : '<STR_LIT>' } ] , u'<STR_LIT:id>' : <NUM_LIT:1> } <EOL> ) <EOL> def test_uploadFile ( self ) : <EOL> """<STR_LIT>""" <EOL> httpretty . register_uri ( httpretty . POST , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( <EOL> additionalMetadata = '<STR_LIT>' , file = dict ( data = six . StringIO ( '<STR_LIT>' ) , filename = '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> body = httpretty . last_request ( ) . body . decode ( ) <EOL> self . assertTrue ( body . find ( '<STR_LIT>' ) != - <NUM_LIT:1> ) <EOL> self . assertTrue ( body . find ( '<STR_LIT>' ) != - <NUM_LIT:1> ) <EOL> self . assertTrue ( body . find ( '<STR_LIT:file>' ) != - <NUM_LIT:1> ) <EOL> self . assertTrue ( body . find ( '<STR_LIT>' ) != - <NUM_LIT:1> ) <EOL> self . assertTrue ( body . find ( '<STR_LIT>' ) != - <NUM_LIT:1> ) <EOL> @ httpretty . activate <EOL> class RequestsOptTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_verify ( self ) : <EOL> """<STR_LIT>""" <EOL> client = Client ( send_opt = dict ( verify = False ) ) <EOL> httpretty . register_uri ( httpretty . GET , '<STR_LIT>' , <EOL> status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> body = json . dumps ( pet_Tom ) <EOL> ) <EOL> resp = client . request ( app . op [ '<STR_LIT>' ] ( petId = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertTrue ( isinstance ( resp . data , Model ) ) <EOL> self . assertEqual ( resp . data , <EOL> { u'<STR_LIT:name>' : '<STR_LIT>' , u'<STR_LIT>' : [ { u'<STR_LIT:id>' : <NUM_LIT:0> , u'<STR_LIT:name>' : '<STR_LIT>' } , { u'<STR_LIT:id>' : <NUM_LIT:1> , u'<STR_LIT:name>' : '<STR_LIT>' } ] , u'<STR_LIT:id>' : <NUM_LIT:1> } <EOL> ) </s>
