<s> __author__ = '<STR_LIT>' <EOL> import unittest <EOL> import gdata . service <EOL> import atom . mock_service <EOL> gdata . service . http_request_handler = atom . mock_service <EOL> class MockRequestTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . request_thumbprint = atom . mock_service . MockRequest ( '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , <EOL> extra_headers = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : '<STR_LIT:b>' } ) <EOL> def testIsMatch ( self ) : <EOL> matching_request = atom . mock_service . MockRequest ( '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , extra_headers = { '<STR_LIT>' : '<STR_LIT:a>' , <EOL> '<STR_LIT>' : '<STR_LIT:b>' , '<STR_LIT>' : '<STR_LIT:c>' } ) <EOL> bad_url = atom . mock_service . MockRequest ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> extra_headers = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : '<STR_LIT:b>' , '<STR_LIT>' : '<STR_LIT:c>' } ) <EOL> bad_header = atom . mock_service . MockRequest ( '<STR_LIT:GET>' , <EOL> '<STR_LIT>' , extra_headers = { '<STR_LIT>' : '<STR_LIT:a>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT:c>' } ) <EOL> bad_verb = atom . mock_service . MockRequest ( '<STR_LIT:POST>' , '<STR_LIT>' , <EOL> data = '<STR_LIT>' , extra_headers = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : '<STR_LIT:b>' } ) <EOL> self . assertEquals ( self . request_thumbprint . IsMatch ( matching_request ) , True ) <EOL> self . assertEquals ( self . request_thumbprint . IsMatch ( bad_url ) , False ) <EOL> self . assertEquals ( self . request_thumbprint . IsMatch ( bad_header ) , True ) <EOL> self . assertEquals ( self . request_thumbprint . IsMatch ( bad_verb ) , False ) <EOL> class HttpRequestTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> atom . mock_service . recordings = [ ] <EOL> self . client = gdata . service . GDataService ( ) <EOL> def testSimpleRecordedGet ( self ) : <EOL> recorded_request = atom . mock_service . MockRequest ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> recorded_response = atom . mock_service . MockHttpResponse ( '<STR_LIT>' , <NUM_LIT:200> , <EOL> '<STR_LIT:OK>' ) <EOL> atom . mock_service . recordings . append ( ( recorded_request , recorded_response ) ) <EOL> response = self . client . Get ( '<STR_LIT>' , converter = str ) <EOL> self . assertEquals ( response , '<STR_LIT>' ) <EOL> self . client . server = '<STR_LIT>' <EOL> raw_response = self . client . handler . HttpRequest ( self . client , '<STR_LIT:GET>' , None , <EOL> '<STR_LIT:/>' ) <EOL> self . assertEquals ( raw_response . read ( ) , '<STR_LIT>' ) <EOL> self . assertEquals ( raw_response . status , <NUM_LIT:200> ) <EOL> self . assertEquals ( raw_response . reason , '<STR_LIT:OK>' ) <EOL> class RecordRealHttpRequestsTest ( unittest . TestCase ) : <EOL> def testRecordAndReuseResponse ( self ) : <EOL> client = gdata . service . GDataService ( ) <EOL> client . server = '<STR_LIT>' <EOL> atom . mock_service . recordings = [ ] <EOL> atom . mock_service . real_request_handler = atom . service <EOL> real_response = atom . mock_service . HttpRequest ( client , '<STR_LIT:GET>' , None , '<STR_LIT>' ) <EOL> atom . mock_service . real_request_handler = None <EOL> mock_response = atom . mock_service . HttpRequest ( client , '<STR_LIT:GET>' , None , '<STR_LIT>' ) <EOL> self . assertEquals ( real_response . reason , mock_response . reason ) <EOL> self . assertEquals ( real_response . status , mock_response . status ) <EOL> self . assertEquals ( real_response . read ( ) , mock_response . read ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
