#NEWLINE# def test_upload_from_file_w_bound_client_multipart( self ) : #NEWLINE# #INDENT# from email.parser import Parser #NEWLINE# import json #NEWLINE# from six.moves.urllib.parse import parse_qsl #NEWLINE# from six.moves.urllib.parse import urlsplit #NEWLINE# ( requested , PATH , BODY ) = self . _upload_from_file_helper ( ) #NEWLINE# self . assertEqual ( len ( requested ) , 1 ) #NEWLINE# req = requested [ 0 ] #NEWLINE# self . assertEqual ( req [ 'method' ] , 'POST' ) #NEWLINE# uri = req [ 'uri' ] #NEWLINE# ( scheme , netloc , path , qs , _ ) = urlsplit ( uri ) #NEWLINE# self . assertEqual ( scheme , 'http' ) #NEWLINE# self . assertEqual ( netloc , 'example.com' ) #NEWLINE# self . assertEqual ( path , ( '/%s' % PATH ) ) #NEWLINE# self . assertEqual ( dict ( parse_qsl ( qs ) ) , { #NEWLINE# #INDENT# 'uploadType' : 'multipart' , #NEWLINE# #UNINDENT# } ) #NEWLINE# parser = Parser ( ) #NEWLINE# ( ctype , boundary ) = [ x . strip ( ) for x in req [ 'headers' ] [ 'content-type' ] . split ( ';' ) ] #NEWLINE# self . assertEqual ( ctype , 'multipart/related' ) #NEWLINE# self . assertTrue ( boundary . startswith ( 'boundary="==' ) ) #NEWLINE# self . assertTrue ( boundary . endswith ( '=="' ) ) #NEWLINE# divider = ( '--' + boundary [ len ( 'boundary="' ) : ( - 1 ) ] ) #NEWLINE# chunks = req [ 'body' ] . split ( divider ) [ 1 : ( - 1 ) ] #NEWLINE# self . assertEqual ( len ( chunks ) , 2 ) #NEWLINE# text_msg = parser . parsestr ( chunks [ 0 ] . strip ( ) ) #NEWLINE# self . assertEqual ( dict ( text_msg . _headers ) , { #NEWLINE# #INDENT# 'Content-Type' : 'application/json' , #NEWLINE# 'MIME-Version' : '1.0' , #NEWLINE# #UNINDENT# } ) #NEWLINE# metadata = json . loads ( text_msg . _payload ) #NEWLINE# load_config = load_config [ 'configuration' ] [ 'load' ] #NEWLINE# DESTINATION_TABLE = { #NEWLINE# #INDENT# 'projectId' : self . PROJECT , #NEWLINE# 'datasetId' : self . DS_NAME , #NEWLINE# 'tableId' : self . TABLE_NAME , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( load_config [ 'destinationTable' ] , DESTINATION_TABLE ) #NEWLINE# self . assertEqual ( load_config [ 'sourceFormat' ] , 'CSV' ) #NEWLINE# app_msg = parser . parsestr ( chunks [ 1 ] . strip ( ) ) #NEWLINE# self . assertEqual ( dict ( app_msg . _headers ) , { #NEWLINE# #INDENT# 'Content-Type' : 'application/octet-stream' , #NEWLINE# 'Content-Transfer-Encoding' : 'binary' , #NEWLINE# 'MIME-Version' : '1.0' , #NEWLINE# #UNINDENT# } ) #NEWLINE# body = BODY . decode ( 'ascii' ) . rstrip ( ) #NEWLINE# body_lines = [ line . strip ( ) for line in body . splitlines ( ) ] #NEWLINE# payload_lines = app_msg . _payload . rstrip ( ) . splitlines ( ) #NEWLINE# self . assertEqual ( payload_lines , body_lines )