@@ -259,12 +259,18 @@ def test_must_download_file_from_s3(self, tempfilemock, botomock):
259259 actual = SamSwaggerReader ._download_from_s3 (self .bucket , self .key , self .version )
260260 self .assertEquals (actual , expected )
261261
262- s3_mock .download_file .assert_called_with (self .bucket , self .key , fp_mock ,
263- ExtraArgs = {"VersionId" : self .version })
262+ s3_mock .download_fileobj .assert_called_with (self .bucket , self .key , fp_mock ,
263+ ExtraArgs = {"VersionId" : self .version })
264264
265265 fp_mock .seek .assert_called_with (0 ) # make sure we seek the file before reading
266266 fp_mock .read .assert_called_with ()
267267
268+ def test_must_fail_on_download_from_s3 (self ):
269+ with self .assertRaises (Exception ) as cm :
270+ SamSwaggerReader ._download_from_s3 (self .bucket , self .key )
271+ self .assertIn (cm .exception .__class__ ,
272+ (botocore .exceptions .NoCredentialsError , botocore .exceptions .ClientError ))
273+
268274 @patch ('samcli.commands.local.lib.swagger.reader.boto3' )
269275 @patch ('samcli.commands.local.lib.swagger.reader.tempfile' )
270276 def test_must_work_without_object_version_id (self , tempfilemock , botomock ):
@@ -281,8 +287,8 @@ def test_must_work_without_object_version_id(self, tempfilemock, botomock):
281287 actual = SamSwaggerReader ._download_from_s3 (self .bucket , self .key )
282288 self .assertEquals (actual , expected )
283289
284- s3_mock .download_file .assert_called_with (self .bucket , self .key , fp_mock ,
285- ExtraArgs = {})
290+ s3_mock .download_fileobj .assert_called_with (self .bucket , self .key , fp_mock ,
291+ ExtraArgs = {})
286292
287293 @patch ('samcli.commands.local.lib.swagger.reader.boto3' )
288294 @patch ('samcli.commands.local.lib.swagger.reader.tempfile' )
@@ -293,8 +299,8 @@ def test_must_log_on_download_exception(self, tempfilemock, botomock):
293299
294300 fp_mock = Mock ()
295301 tempfilemock .TemporaryFile .return_value .__enter__ .return_value = fp_mock # mocking context manager
296- s3_mock .download_file .side_effect = botocore .exceptions .ClientError ({"Error" : {}},
297- "download_file" )
302+ s3_mock .download_fileobj .side_effect = botocore .exceptions .ClientError ({"Error" : {}},
303+ "download_file" )
298304
299305 with self .assertRaises (botocore .exceptions .ClientError ):
300306 SamSwaggerReader ._download_from_s3 (self .bucket , self .key )
0 commit comments