#NEWLINE# def test_basic( self ) : #NEWLINE# #INDENT# request = { #NEWLINE# #INDENT# 'uri' : mox . Func ( self . saver ( 'uri' ) ) , #NEWLINE# 'method' : 'POST' , #NEWLINE# 'headers' : mox . Func ( self . saver ( 'headers' ) ) , #NEWLINE# 'body' : mox . Func ( self . saver ( 'body' ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# response = { #NEWLINE# #INDENT# 'status' : 201 , #NEWLINE# #UNINDENT# } #NEWLINE# http = typepad . TypePadClient ( ) #NEWLINE# typepad . client = http #NEWLINE# http . add_credentials ( OAuthConsumer ( 'consumertoken' , 'consumersecret' ) , OAuthToken ( 'tokentoken' , 'tokensecret' ) , domain = 'api.typepad.com' ) #NEWLINE# mock = mox . Mox ( ) #NEWLINE# mock . StubOutWithMock ( http , 'request' ) #NEWLINE# http . request ( ** request ) . AndReturn ( ( response , '' ) ) #NEWLINE# mock . ReplayAll ( ) #NEWLINE# asset = typepad . Photo ( ) #NEWLINE# asset . title = 'Fake photo' #NEWLINE# asset . content = 'This is a made-up photo for testing automated browser style upload.' #NEWLINE# fileobj = StringIO ( 'hi hello pretend file' ) #NEWLINE# brupload = typepad . BrowserUploadEndpoint ( ) #NEWLINE# brupload . upload ( asset , fileobj , 'image/png' , post_type = 'photo' ) #NEWLINE# mock . VerifyAll ( ) #NEWLINE# self . assert_ ( self . uri ) #NEWLINE# self . assert_ ( self . uri . startswith ( 'https://api.typepad.com/browser-upload.json' ) ) #NEWLINE# uriparts = list ( urlparse ( self . uri ) ) #NEWLINE# querydict = cgi . parse_qs ( uriparts [ 4 ] ) #NEWLINE# self . assert_ ( self . headers ) #NEWLINE# self . assert_ ( self . body ) #NEWLINE# responsemsg = self . message_from_response ( self . headers , self . body ) #NEWLINE# content_type = responsemsg . get_content_type ( ) #NEWLINE# self . assert_ ( content_type ) #NEWLINE# self . assert_ ( ( not responsemsg . defects ) ) #NEWLINE# self . assert_ ( ( '\r\nContent-Type:' in self . body ) ) #NEWLINE# boundary = responsemsg . get_param ( 'boundary' ) #NEWLINE# self . assert_ ( ( ( boundary + '\r\n' ) in self . body ) ) #NEWLINE# self . assert_ ( ( 'oauth_signature' in querydict ) ) #NEWLINE# self . assert_ ( ( 'authorization' not in responsemsg ) ) #NEWLINE# self . assert_ ( ( 'Authorization' not in responsemsg ) ) #NEWLINE# bodyparts = responsemsg . get_payload ( ) #NEWLINE# self . assertEquals ( len ( bodyparts ) , 3 ) #NEWLINE# bodyparts = dict ( ( ( part . get_param ( 'name' , header = 'content-disposition' ) , part ) for part in bodyparts ) ) #NEWLINE# self . assertEquals ( bodyparts [ 'post_type' ] . get_payload ( ) , 'photo' ) #NEWLINE# self . assert_ ( ( 'redirect_to' not in bodyparts ) ) #NEWLINE# asset_json = bodyparts [ 'asset' ] . get_payload ( ) #NEWLINE# self . assert_ ( utils . json_equals ( { #NEWLINE# #INDENT# 'title' : 'Fake photo' , #NEWLINE# 'content' : 'This is a made-up photo for testing automated browser style upload.' , #NEWLINE# 'objectType' : 'Photo' , #NEWLINE# #UNINDENT# } , asset_json ) ) #NEWLINE# filepart = bodyparts [ 'file' ] #NEWLINE# self . assertEquals ( filepart . get_payload ( decode = False ) , 'hi hello pretend file' ) #NEWLINE# filelength = filepart . get ( 'content-length' ) #NEWLINE# self . assertEquals ( int ( filelength ) , len ( 'hi hello pretend file' ) ) #NEWLINE# filename = filepart . get_param ( 'filename' , header = 'content-disposition' ) #NEWLINE# self . assert_ ( filename )