<s> import httplib <EOL> from testcases import TestServerTestCase <EOL> from django . utils import simplejson as json <EOL> class HTTPTestCase ( TestServerTestCase ) : <EOL> def setUp ( self ) : <EOL> self . start_test_server ( address = '<STR_LIT:localhost>' , port = <NUM_LIT> ) <EOL> def tearDown ( self ) : <EOL> self . stop_test_server ( ) <EOL> def get_connection ( self ) : <EOL> return httplib . HTTPConnection ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> def test_get_apis_json ( self ) : <EOL> connection = self . get_connection ( ) <EOL> connection . request ( '<STR_LIT:GET>' , '<STR_LIT>' , headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } ) <EOL> response = connection . getresponse ( ) <EOL> connection . close ( ) <EOL> data = response . read ( ) <EOL> self . assertEqual ( response . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( data , '<STR_LIT>' ) <EOL> def test_get_apis_xml ( self ) : <EOL> connection = self . get_connection ( ) <EOL> connection . request ( '<STR_LIT:GET>' , '<STR_LIT>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> response = connection . getresponse ( ) <EOL> connection . close ( ) <EOL> data = response . read ( ) <EOL> self . assertEqual ( response . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( data , '<STR_LIT>' ) <EOL> def test_get_list ( self ) : <EOL> connection = self . get_connection ( ) <EOL> connection . request ( '<STR_LIT:GET>' , '<STR_LIT>' , headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } ) <EOL> response = connection . getresponse ( ) <EOL> connection . close ( ) <EOL> self . assertEqual ( response . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . read ( ) , '<STR_LIT>' ) <EOL> def test_post_object ( self ) : <EOL> connection = self . get_connection ( ) <EOL> post_data = '<STR_LIT>' <EOL> connection . request ( '<STR_LIT:POST>' , '<STR_LIT>' , body = post_data , headers = { '<STR_LIT>' : '<STR_LIT:application/json>' , '<STR_LIT>' : '<STR_LIT:application/json>' } ) <EOL> response = connection . getresponse ( ) <EOL> self . assertEqual ( response . status , <NUM_LIT> ) <EOL> self . assertEqual ( dict ( response . getheaders ( ) ) [ '<STR_LIT:location>' ] , '<STR_LIT>' ) <EOL> connection . request ( '<STR_LIT:GET>' , '<STR_LIT>' , headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } ) <EOL> response = connection . getresponse ( ) <EOL> connection . close ( ) <EOL> self . assertEqual ( response . status , <NUM_LIT:200> ) <EOL> data = response . read ( ) <EOL> obj = json . loads ( data ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> def test_cache_control ( self ) : <EOL> """<STR_LIT>""" <EOL> connection = self . get_connection ( ) <EOL> connection . request ( '<STR_LIT:GET>' , '<STR_LIT>' , headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } ) <EOL> response = connection . getresponse ( ) <EOL> connection . close ( ) <EOL> self . assertEqual ( response . status , <NUM_LIT:200> ) <EOL> headers = dict ( response . getheaders ( ) ) <EOL> self . assertEqual ( headers [ '<STR_LIT>' ] , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> self . assertTrue ( '<STR_LIT>' in response . read ( ) ) </s>
