<s> import unittest <EOL> import os <EOL> import utils <EOL> import sdk <EOL> allow_multipart = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> require_file_size = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class Multipart ( unittest . TestCase ) : <EOL> num_parts = <NUM_LIT:3> <EOL> chunk_size = <NUM_LIT> <EOL> def test_multipart ( self ) : <EOL> if self . account . service not in allow_multipart : <EOL> self . skipTest ( "<STR_LIT>" ) <EOL> acc = self . account <EOL> folder = utils . create_or_get_test_folder ( acc ) <EOL> multipart_data = { <EOL> "<STR_LIT>" : folder . id , <EOL> "<STR_LIT:name>" : "<STR_LIT>" <EOL> } <EOL> if self . account . service in require_file_size : <EOL> multipart_data [ "<STR_LIT:size>" ] = self . num_parts * self . chunk_size <EOL> multipart = acc . multipart . create ( data = multipart_data ) <EOL> new_multipart = acc . multipart . retrieve ( id = multipart . id ) <EOL> self . assertEqual ( str ( new_multipart . id ) , str ( multipart . id ) ) <EOL> self . assertEqual ( str ( new_multipart . account ) , str ( multipart . account ) ) <EOL> for x in range ( <NUM_LIT:1> , self . num_parts + <NUM_LIT:1> ) : <EOL> data = os . urandom ( self . chunk_size ) <EOL> response = multipart . upload_chunk ( part_number = x , data = data ) <EOL> self . assertTrue ( response ) <EOL> file_result = multipart . complete ( ) <EOL> self . assertIsInstance ( file_result , sdk . resources . File ) <EOL> if file_result . get ( '<STR_LIT>' ) : <EOL> if file_result . parent . get ( '<STR_LIT:name>' ) : <EOL> self . assertEqual ( <EOL> folder . name . lower ( ) , file_result . parent . name . lower ( ) ) <EOL> elif file_result . parent . get ( '<STR_LIT:id>' ) : <EOL> folder_metadata = acc . folders . retrieve ( <EOL> id = file_result . parent . id ) <EOL> folder_name = folder_metadata . get ( '<STR_LIT:name>' ) <EOL> if folder_name : <EOL> self . assertEqual ( folder . name , folder_name ) <EOL> if file_result . get ( '<STR_LIT:size>' ) : <EOL> total_size = self . num_parts * self . chunk_size <EOL> self . assertEqual ( total_size , file_result . get ( '<STR_LIT:size>' ) ) <EOL> multipart_data [ "<STR_LIT:size>" ] = <NUM_LIT:1> * self . chunk_size <EOL> multipart = acc . multipart . create ( <EOL> data = multipart_data , params = { '<STR_LIT>' : '<STR_LIT:true>' } ) <EOL> response = multipart . upload_chunk ( <EOL> part_number = <NUM_LIT:1> , data = os . urandom ( self . chunk_size ) ) <EOL> self . assertTrue ( response ) <EOL> overwrite_file_result = multipart . complete ( ) <EOL> self . assertIsInstance ( overwrite_file_result , sdk . resources . File ) <EOL> self . assertEqual ( file_result . name , overwrite_file_result . name ) <EOL> multipart = acc . multipart . create ( <EOL> data = multipart_data , params = { '<STR_LIT>' : '<STR_LIT:false>' } ) <EOL> response = multipart . upload_chunk ( <EOL> part_number = <NUM_LIT:1> , data = os . urandom ( self . chunk_size ) ) <EOL> self . assertTrue ( response ) <EOL> no_overwrite_file_result = multipart . complete ( ) <EOL> self . assertIsInstance ( overwrite_file_result , sdk . resources . File ) <EOL> self . assertNotEqual ( file_result . name , no_overwrite_file_result . name ) <EOL> def test_cases ( ) : <EOL> return [ utils . create_test_case ( acc , Multipart ) for acc in utils . accounts ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> suite = utils . create_suite ( test_cases ( ) ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) </s>
