#NEWLINE# def testDownloadReportToFile( self ) : #NEWLINE# #INDENT# report_format = 'csv' #NEWLINE# report_job_id = 't68t3278y429' #NEWLINE# report_download_url = 'http://google.com/something' #NEWLINE# report_contents = 'THIS IS YOUR REPORT!' #NEWLINE# fake_request = StringIO . StringIO ( ) #NEWLINE# fake_request . write ( report_contents ) #NEWLINE# fake_request . seek ( 0 ) #NEWLINE# outfile = StringIO . StringIO ( ) #NEWLINE# self . report_service . getReportDownloadURL . return_value = report_download_url #NEWLINE# with mock . patch ( ( 'urllib2.urlopen' if ( sys . version_info [ 0 ] == 2 ) else 'urllib.request.urlopen' ) ) as mock_urlopen : #NEWLINE# #INDENT# mock_urlopen . return_value = fake_request #NEWLINE# self . report_downloader . DownloadReportToFile ( report_job_id , report_format , outfile ) #NEWLINE# mock_urlopen . assert_called_once_with ( report_download_url ) #NEWLINE# self . assertEqual ( report_contents , outfile . getvalue ( ) )