<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> from salttesting import TestCase , skipIf <EOL> from salttesting . mock import ( <EOL> create_autospec , <EOL> MagicMock , <EOL> patch , <EOL> NO_MOCK , <EOL> NO_MOCK_REASON <EOL> ) <EOL> from salttesting . helpers import ensure_in_syspath <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . modules import etcd_mod <EOL> from salt . utils import etcd_util <EOL> etcd_mod . __opts__ = { } <EOL> etcd_mod . __utils__ = { } <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class EtcdModTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> self . instance = create_autospec ( etcd_util . EtcdClient ) <EOL> self . EtcdClientMock = MagicMock ( ) <EOL> self . EtcdClientMock . return_value = self . instance <EOL> def tearDown ( self ) : <EOL> self . instance = None <EOL> self . EtcdClientMock = None <EOL> def test_get ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( etcd_mod . __utils__ , { '<STR_LIT>' : self . EtcdClientMock } ) : <EOL> self . instance . get . return_value = '<STR_LIT>' <EOL> self . assertEqual ( etcd_mod . get_ ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . instance . get . assert_called_with ( '<STR_LIT>' , recurse = False ) <EOL> self . instance . tree . return_value = { } <EOL> self . assertEqual ( etcd_mod . get_ ( '<STR_LIT>' , recurse = True ) , { } ) <EOL> self . instance . tree . assert_called_with ( '<STR_LIT>' ) <EOL> self . instance . get . side_effect = Exception <EOL> self . assertRaises ( Exception , etcd_mod . get_ , '<STR_LIT>' ) <EOL> def test_set ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( etcd_mod . __utils__ , { '<STR_LIT>' : self . EtcdClientMock } ) : <EOL> self . instance . set . return_value = '<STR_LIT>' <EOL> self . assertEqual ( etcd_mod . set_ ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . instance . set . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , directory = False , ttl = None ) <EOL> self . instance . set . return_value = True <EOL> self . assertEqual ( etcd_mod . set_ ( '<STR_LIT>' , '<STR_LIT>' , directory = True ) , True ) <EOL> self . instance . set . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , directory = True , ttl = None ) <EOL> self . assertEqual ( etcd_mod . set_ ( '<STR_LIT>' , '<STR_LIT>' , directory = True , ttl = <NUM_LIT:5> ) , True ) <EOL> self . instance . set . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , directory = True , ttl = <NUM_LIT:5> ) <EOL> self . assertEqual ( etcd_mod . set_ ( '<STR_LIT>' , '<STR_LIT>' , None , <NUM_LIT:10> , True ) , True ) <EOL> self . instance . set . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , directory = True , ttl = <NUM_LIT:10> ) <EOL> self . instance . set . side_effect = Exception <EOL> self . assertRaises ( Exception , etcd_mod . set_ , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_update ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( etcd_mod . __utils__ , { '<STR_LIT>' : self . EtcdClientMock } ) : <EOL> args = { <EOL> '<STR_LIT:x>' : { <EOL> '<STR_LIT:y>' : { <EOL> '<STR_LIT:a>' : '<STR_LIT:1>' , <EOL> '<STR_LIT:b>' : '<STR_LIT:2>' , <EOL> } <EOL> } , <EOL> '<STR_LIT:z>' : '<STR_LIT:4>' , <EOL> '<STR_LIT:d>' : { } , <EOL> } <EOL> result = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : { } , <EOL> } <EOL> self . instance . update . return_value = result <EOL> self . assertDictEqual ( etcd_mod . update ( args , path = '<STR_LIT>' ) , result ) <EOL> self . instance . update . assert_called_with ( args , '<STR_LIT>' ) <EOL> self . assertDictEqual ( etcd_mod . update ( args ) , result ) <EOL> self . instance . update . assert_called_with ( args , '<STR_LIT>' ) <EOL> def test_ls ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( etcd_mod . __utils__ , { '<STR_LIT>' : self . EtcdClientMock } ) : <EOL> self . instance . ls . return_value = { '<STR_LIT>' : { } } <EOL> self . assertDictEqual ( etcd_mod . ls_ ( '<STR_LIT>' ) , { '<STR_LIT>' : { } } ) <EOL> self . instance . ls . assert_called_with ( '<STR_LIT>' ) <EOL> self . instance . ls . return_value = { '<STR_LIT:/>' : { } } <EOL> self . assertDictEqual ( etcd_mod . ls_ ( ) , { '<STR_LIT:/>' : { } } ) <EOL> self . instance . ls . assert_called_with ( '<STR_LIT:/>' ) <EOL> self . instance . ls . side_effect = Exception <EOL> self . assertRaises ( Exception , etcd_mod . ls_ , '<STR_LIT>' ) <EOL> def test_rm ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( etcd_mod . __utils__ , { '<STR_LIT>' : self . EtcdClientMock } ) : <EOL> self . instance . rm . return_value = False <EOL> self . assertFalse ( etcd_mod . rm_ ( '<STR_LIT>' ) ) <EOL> self . instance . rm . assert_called_with ( '<STR_LIT>' , recurse = False ) <EOL> self . instance . rm . return_value = True <EOL> self . assertTrue ( etcd_mod . rm_ ( '<STR_LIT>' , recurse = True ) ) <EOL> self . instance . rm . assert_called_with ( '<STR_LIT>' , recurse = True ) <EOL> self . instance . rm . side_effect = Exception <EOL> self . assertRaises ( Exception , etcd_mod . rm_ , '<STR_LIT>' ) <EOL> def test_tree ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( etcd_mod . __utils__ , { '<STR_LIT>' : self . EtcdClientMock } ) : <EOL> self . instance . tree . return_value = { } <EOL> self . assertDictEqual ( etcd_mod . tree ( '<STR_LIT>' ) , { } ) <EOL> self . instance . tree . assert_called_with ( '<STR_LIT>' ) <EOL> self . assertDictEqual ( etcd_mod . tree ( ) , { } ) <EOL> self . instance . tree . assert_called_with ( '<STR_LIT:/>' ) <EOL> self . instance . tree . side_effect = Exception <EOL> self . assertRaises ( Exception , etcd_mod . tree , '<STR_LIT>' ) <EOL> def test_watch ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( etcd_mod . __utils__ , { '<STR_LIT>' : self . EtcdClientMock } ) : <EOL> self . instance . watch . return_value = { <EOL> '<STR_LIT:value>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:key>' : '<STR_LIT>' <EOL> } <EOL> self . assertEqual ( etcd_mod . watch ( '<STR_LIT>' ) , self . instance . watch . return_value ) <EOL> self . instance . watch . assert_called_with ( '<STR_LIT>' , recurse = False , timeout = <NUM_LIT:0> , index = None ) <EOL> self . instance . watch . return_value [ '<STR_LIT>' ] = True <EOL> self . assertEqual ( etcd_mod . watch ( '<STR_LIT>' , recurse = True , timeout = <NUM_LIT:5> , index = <NUM_LIT:10> ) , <EOL> self . instance . watch . return_value ) <EOL> self . instance . watch . assert_called_with ( '<STR_LIT>' , recurse = True , timeout = <NUM_LIT:5> , index = <NUM_LIT:10> ) <EOL> self . assertEqual ( etcd_mod . watch ( '<STR_LIT>' , True , None , <NUM_LIT:5> , <NUM_LIT:10> ) , <EOL> self . instance . watch . return_value ) <EOL> self . instance . watch . assert_called_with ( '<STR_LIT>' , recurse = True , timeout = <NUM_LIT:5> , index = <NUM_LIT:10> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( EtcdModTestCase , needs_daemon = False ) </s>
