<s> import os <EOL> import zipfile <EOL> from contextlib import closing <EOL> from awscli . testutils import unittest <EOL> from awscli . testutils import BaseAWSCommandParamsTest <EOL> from awscli . testutils import FileCreator <EOL> class BaseLambdaTests ( BaseAWSCommandParamsTest ) : <EOL> def setUp ( self ) : <EOL> super ( BaseLambdaTests , self ) . setUp ( ) <EOL> self . files = FileCreator ( ) <EOL> self . temp_file = self . files . create_file ( <EOL> '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . zip_file = os . path . join ( self . files . rootdir , '<STR_LIT>' ) <EOL> with closing ( zipfile . ZipFile ( self . zip_file , '<STR_LIT:w>' ) ) as f : <EOL> f . write ( self . temp_file ) <EOL> with open ( self . zip_file , '<STR_LIT:rb>' ) as f : <EOL> self . zip_file_contents = f . read ( ) <EOL> def tearDown ( self ) : <EOL> super ( BaseLambdaTests , self ) . tearDown ( ) <EOL> self . files . remove_all ( ) <EOL> class TestCreateFunction ( BaseLambdaTests ) : <EOL> prefix = '<STR_LIT>' <EOL> def test_create_function_with_file ( self ) : <EOL> cmdline = self . prefix <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' % self . zip_file <EOL> result = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : self . zip_file_contents } <EOL> } <EOL> self . assert_params_for_cmd ( cmdline , result ) <EOL> def test_create_function_with_code_argument ( self ) : <EOL> cmdline = self . prefix <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> result = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> } <EOL> self . assert_params_for_cmd ( cmdline , result ) <EOL> def test_create_function_with_code_and_zipfile_argument ( self ) : <EOL> cmdline = self . prefix <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' % self . zip_file <EOL> result = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . zip_file_contents } <EOL> } <EOL> self . assert_params_for_cmd ( cmdline , result ) <EOL> def test_create_function_with_zip_file_in_code_argument ( self ) : <EOL> cmdline = self . prefix <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> stdout , stderr , rc = self . run_cmd ( cmdline , expected_rc = <NUM_LIT:255> ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> stderr ) <EOL> def test_create_function_with_invalid_file_contents ( self ) : <EOL> cmdline = self . prefix <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> stdout , stderr , rc = self . run_cmd ( cmdline , expected_rc = <NUM_LIT:255> ) <EOL> self . assertIn ( '<STR_LIT>' , stderr ) <EOL> self . assertIn ( '<STR_LIT>' , stderr ) <EOL> def test_not_using_fileb_prefix ( self ) : <EOL> cmdline = self . prefix <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' % self . zip_file <EOL> stdout , stderr , rc = self . run_cmd ( cmdline , expected_rc = <NUM_LIT:255> ) <EOL> self . assertIn ( '<STR_LIT>' , stderr ) <EOL> class TestUpdateFunctionCode ( BaseLambdaTests ) : <EOL> prefix = '<STR_LIT>' <EOL> def test_not_using_fileb_prefix ( self ) : <EOL> cmdline = self . prefix + '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' <EOL> stdout , stderr , rc = self . run_cmd ( cmdline , expected_rc = <NUM_LIT:255> ) <EOL> self . assertIn ( '<STR_LIT>' , stderr ) <EOL> self . assertIn ( '<STR_LIT>' , stderr ) <EOL> def test_using_fileb_prefix_succeeds ( self ) : <EOL> cmdline = self . prefix <EOL> cmdline += '<STR_LIT>' <EOL> cmdline += '<STR_LIT>' % self . zip_file <EOL> result = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . zip_file_contents , <EOL> } <EOL> self . assert_params_for_cmd ( cmdline , result ) </s>
