<s> from tests import unittest <EOL> import mock <EOL> from botocore . exceptions import ClientError <EOL> from boto3 . s3 import inject <EOL> class TestInjectTransferMethods ( unittest . TestCase ) : <EOL> def test_inject_upload_download_file_to_client ( self ) : <EOL> class_attributes = { } <EOL> inject . inject_s3_transfer_methods ( class_attributes = class_attributes ) <EOL> self . assertIn ( '<STR_LIT>' , class_attributes ) <EOL> self . assertIn ( '<STR_LIT>' , class_attributes ) <EOL> def test_upload_file_proxies_to_transfer_object ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as transfer : <EOL> inject . upload_file ( mock . sentinel . CLIENT , <EOL> Filename = '<STR_LIT:filename>' , <EOL> Bucket = '<STR_LIT>' , Key = '<STR_LIT:key>' ) <EOL> transfer . return_value . upload_file . assert_called_with ( <EOL> filename = '<STR_LIT:filename>' , bucket = '<STR_LIT>' , key = '<STR_LIT:key>' , <EOL> extra_args = None , callback = None ) <EOL> def test_download_file_proxies_to_transfer_object ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as transfer : <EOL> inject . download_file ( <EOL> mock . sentinel . CLIENT , <EOL> Bucket = '<STR_LIT>' , Key = '<STR_LIT:key>' , <EOL> Filename = '<STR_LIT:filename>' ) <EOL> transfer . return_value . download_file . assert_called_with ( <EOL> bucket = '<STR_LIT>' , key = '<STR_LIT:key>' , filename = '<STR_LIT:filename>' , <EOL> extra_args = None , callback = None ) <EOL> class TestBucketLoad ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . client = mock . Mock ( ) <EOL> self . resource = mock . Mock ( ) <EOL> self . resource . meta . client = self . client <EOL> def test_bucket_load_finds_bucket ( self ) : <EOL> self . resource . name = '<STR_LIT>' <EOL> self . client . list_buckets . return_value = { <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:Name>' : self . resource . name , '<STR_LIT>' : <NUM_LIT:2> } , <EOL> ] , <EOL> } <EOL> inject . bucket_load ( self . resource ) <EOL> self . assertEqual ( <EOL> self . resource . meta . data , <EOL> { '<STR_LIT:Name>' : self . resource . name , '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> def test_bucket_load_raise_error ( self ) : <EOL> self . resource . name = '<STR_LIT>' <EOL> self . client . list_buckets . return_value = { <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } , <EOL> { '<STR_LIT:Name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> } , <EOL> ] , <EOL> } <EOL> with self . assertRaises ( ClientError ) : <EOL> inject . bucket_load ( self . resource ) <EOL> class TestBucketTransferMethods ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . bucket = mock . Mock ( name = '<STR_LIT>' ) <EOL> def test_upload_file_proxies_to_meta_client ( self ) : <EOL> inject . bucket_upload_file ( self . bucket , Filename = '<STR_LIT:foo>' , Key = '<STR_LIT:key>' ) <EOL> self . bucket . meta . client . upload_file . assert_called_with ( <EOL> Filename = '<STR_LIT:foo>' , Bucket = self . bucket . name , Key = '<STR_LIT:key>' , <EOL> ExtraArgs = None , Callback = None , Config = None ) <EOL> def test_download_file_proxies_to_meta_client ( self ) : <EOL> inject . bucket_download_file ( self . bucket , Key = '<STR_LIT:key>' , Filename = '<STR_LIT:foo>' ) <EOL> self . bucket . meta . client . download_file . assert_called_with ( <EOL> Bucket = self . bucket . name , Key = '<STR_LIT:key>' , Filename = '<STR_LIT:foo>' , <EOL> ExtraArgs = None , Callback = None , Config = None ) <EOL> class TestObjectTransferMethods ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . obj = mock . Mock ( bucket_name = '<STR_LIT>' , key = '<STR_LIT>' ) <EOL> def test_upload_file_proxies_to_meta_client ( self ) : <EOL> inject . object_upload_file ( self . obj , Filename = '<STR_LIT:foo>' ) <EOL> self . obj . meta . client . upload_file . assert_called_with ( <EOL> Filename = '<STR_LIT:foo>' , Bucket = self . obj . bucket_name , Key = self . obj . key , <EOL> ExtraArgs = None , Callback = None , Config = None ) <EOL> def test_download_file_proxies_to_meta_client ( self ) : <EOL> inject . object_download_file ( self . obj , Filename = '<STR_LIT:foo>' ) <EOL> self . obj . meta . client . download_file . assert_called_with ( <EOL> Bucket = self . obj . bucket_name , Key = self . obj . key , Filename = '<STR_LIT:foo>' , <EOL> ExtraArgs = None , Callback = None , Config = None ) <EOL> class TestObejctSummaryLoad ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . client = mock . Mock ( ) <EOL> self . resource = mock . Mock ( ) <EOL> self . resource . meta . client = self . client <EOL> self . head_object_response = { <EOL> '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . client . head_object . return_value = self . head_object_response <EOL> def test_object_summary_load ( self ) : <EOL> inject . object_summary_load ( self . resource ) <EOL> self . assertEqual ( <EOL> self . resource . meta . data , { '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_can_handle_missing_content_length ( self ) : <EOL> self . head_object_response . pop ( '<STR_LIT>' ) <EOL> inject . object_summary_load ( self . resource ) <EOL> self . assertEqual ( self . resource . meta . data , { '<STR_LIT>' : '<STR_LIT>' } ) </s>
