<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> from salttesting import skipIf , TestCase <EOL> from salttesting . mock import ( <EOL> NO_MOCK , <EOL> NO_MOCK_REASON , <EOL> MagicMock , <EOL> patch ) <EOL> from salttesting . helpers import ensure_in_syspath <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . states import boto_ec2 <EOL> boto_ec2 . __salt__ = { } <EOL> boto_ec2 . __opts__ = { } <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class BotoEc2TestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def test_key_present ( self ) : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> upublic = '<STR_LIT>' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> mock = MagicMock ( side_effect = [ True , False , False ] ) <EOL> mock_bool = MagicMock ( side_effect = [ IOError , True ] ) <EOL> with patch . dict ( boto_ec2 . __salt__ , { '<STR_LIT>' : mock , <EOL> '<STR_LIT>' : mock_bool } ) : <EOL> comt = ( '<STR_LIT>' . format ( name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt } ) <EOL> self . assertDictEqual ( boto_ec2 . key_present ( name ) , ret ) <EOL> comt = ( '<STR_LIT>' . format ( upublic ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : False } ) <EOL> self . assertDictEqual ( boto_ec2 . key_present ( name , <EOL> upload_public = upublic ) , <EOL> ret ) <EOL> with patch . dict ( boto_ec2 . __opts__ , { '<STR_LIT:test>' : True } ) : <EOL> comt = ( '<STR_LIT>' . format ( name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( boto_ec2 . key_present <EOL> ( name , upload_public = upublic ) , ret ) <EOL> def test_key_absent ( self ) : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> mock = MagicMock ( side_effect = [ False , True ] ) <EOL> with patch . dict ( boto_ec2 . __salt__ , { '<STR_LIT>' : mock } ) : <EOL> comt = ( '<STR_LIT>' . format ( name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt } ) <EOL> self . assertDictEqual ( boto_ec2 . key_absent ( name ) , ret ) <EOL> with patch . dict ( boto_ec2 . __opts__ , { '<STR_LIT:test>' : True } ) : <EOL> comt = ( '<STR_LIT>' . format ( name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( boto_ec2 . key_absent ( name ) , ret ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( BotoEc2TestCase , needs_daemon = False ) </s>
