<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> ) <EOL> from salttesting . helpers import ensure_in_syspath <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . states import postgres_cluster <EOL> postgres_cluster . __opts__ = { } <EOL> postgres_cluster . __salt__ = { } <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class PostgresClusterTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def test_present ( self ) : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> version = '<STR_LIT>' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> mock_t = MagicMock ( return_value = True ) <EOL> mock_f = MagicMock ( return_value = False ) <EOL> infos = { '<STR_LIT>' . format ( version , name ) : { } } <EOL> mock = MagicMock ( return_value = infos ) <EOL> with patch . dict ( postgres_cluster . __salt__ , <EOL> { '<STR_LIT>' : mock , <EOL> '<STR_LIT>' : mock_t , <EOL> '<STR_LIT>' : mock_t , <EOL> } ) : <EOL> comt = ( '<STR_LIT>' . format ( version , name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : True } ) <EOL> self . assertDictEqual ( postgres_cluster . present ( version , name ) , ret ) <EOL> infos [ '<STR_LIT>' . format ( version , name ) ] [ '<STR_LIT:port>' ] = <NUM_LIT> <EOL> comt = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( version , name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : False } ) <EOL> self . assertDictEqual ( postgres_cluster . present ( version , name , port = <NUM_LIT> ) , ret ) <EOL> infos [ '<STR_LIT>' . format ( version , name ) ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> comt = ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( version , name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : False } ) <EOL> self . assertDictEqual ( postgres_cluster . present ( version , name , port = <NUM_LIT> ) , ret ) <EOL> with patch . dict ( postgres_cluster . __salt__ , <EOL> { '<STR_LIT>' : mock , <EOL> '<STR_LIT>' : mock_f , <EOL> '<STR_LIT>' : mock_t , <EOL> } ) : <EOL> comt = '<STR_LIT>' . format ( version , name ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : { '<STR_LIT>' . format ( version , name ) : '<STR_LIT>' } <EOL> } ) <EOL> self . assertDictEqual ( postgres_cluster . present ( version , name ) , <EOL> ret ) <EOL> with patch . dict ( postgres_cluster . __opts__ , { '<STR_LIT:test>' : True } ) : <EOL> comt = '<STR_LIT>' . format ( version , name ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : None , '<STR_LIT>' : { } } ) <EOL> self . assertDictEqual ( postgres_cluster . present ( version , name ) , <EOL> ret ) <EOL> with patch . dict ( postgres_cluster . __salt__ , <EOL> { '<STR_LIT>' : mock , <EOL> '<STR_LIT>' : mock_f , <EOL> '<STR_LIT>' : mock_f , <EOL> } ) : <EOL> comt = '<STR_LIT>' . format ( version , name ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : False } ) <EOL> self . assertDictEqual ( postgres_cluster . present ( version , name ) , <EOL> ret ) <EOL> def test_absent ( self ) : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> version = '<STR_LIT>' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> mock_t = MagicMock ( return_value = True ) <EOL> mock = MagicMock ( side_effect = [ True , True , False ] ) <EOL> with patch . dict ( postgres_cluster . __salt__ , <EOL> { '<STR_LIT>' : mock , <EOL> '<STR_LIT>' : mock_t } ) : <EOL> with patch . dict ( postgres_cluster . __opts__ , { '<STR_LIT:test>' : True } ) : <EOL> comt = ( '<STR_LIT>' . format ( version , name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( postgres_cluster . absent ( version , name ) , ret ) <EOL> with patch . dict ( postgres_cluster . __opts__ , { '<STR_LIT:test>' : False } ) : <EOL> comt = ( '<STR_LIT>' . format ( version , name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : { name : '<STR_LIT>' } } ) <EOL> self . assertDictEqual ( postgres_cluster . absent ( version , name ) , ret ) <EOL> comt = ( '<STR_LIT>' <EOL> . format ( version , name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : True , '<STR_LIT>' : { } } ) <EOL> self . assertDictEqual ( postgres_cluster . absent ( version , name ) , ret ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( PostgresClusterTestCase , needs_daemon = False ) </s>
