<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import sys <EOL> from salttesting import TestCase , skipIf <EOL> from salttesting . helpers import ensure_in_syspath <EOL> from salttesting . mock import ( <EOL> MagicMock , <EOL> patch , <EOL> NO_MOCK , <EOL> NO_MOCK_REASON <EOL> ) <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . states import network <EOL> network . __salt__ = { } <EOL> network . __grains__ = { } <EOL> network . __opts__ = { } <EOL> class MockNetwork ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ staticmethod <EOL> def interfaces ( ) : <EOL> '''<STR_LIT>''' <EOL> return { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> } } <EOL> class MockGrains ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ staticmethod <EOL> def grains ( lis , bol ) : <EOL> '''<STR_LIT>''' <EOL> return { '<STR_LIT:A>' : '<STR_LIT:B>' } <EOL> @ skipIf ( sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) , '<STR_LIT>' ) <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class NetworkTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> @ patch ( '<STR_LIT>' , MockNetwork ( ) ) <EOL> @ patch ( '<STR_LIT>' , MockGrains ( ) ) <EOL> def test_managed ( self ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> change = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' } <EOL> mock = MagicMock ( side_effect = [ AttributeError , '<STR_LIT:A>' , '<STR_LIT:A>' , '<STR_LIT:A>' , '<STR_LIT:A>' , '<STR_LIT:A>' ] ) <EOL> with patch . dict ( network . __salt__ , { "<STR_LIT>" : mock } ) : <EOL> self . assertDictEqual ( network . managed ( '<STR_LIT>' , <EOL> '<STR_LIT>' , test = '<STR_LIT:a>' ) , ret ) <EOL> mock = MagicMock ( return_value = '<STR_LIT:B>' ) <EOL> with patch . dict ( network . __salt__ , { "<STR_LIT>" : mock } ) : <EOL> mock = MagicMock ( side_effect = AttributeError ) <EOL> with patch . dict ( network . __salt__ , { "<STR_LIT>" : mock } ) : <EOL> self . assertDictEqual ( network . managed ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> test = '<STR_LIT:a>' ) , ret ) <EOL> ret . update ( { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( network . managed ( '<STR_LIT>' , '<STR_LIT>' , <EOL> test = '<STR_LIT:a>' ) , ret ) <EOL> mock = MagicMock ( return_value = True ) <EOL> with patch . dict ( network . __salt__ , { "<STR_LIT>" : mock } ) : <EOL> with patch . dict ( network . __salt__ , { "<STR_LIT>" : mock } ) : <EOL> ret . update ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : change } ) <EOL> self . assertDictEqual ( network . managed ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ret ) <EOL> with patch . dict ( network . __grains__ , { "<STR_LIT:A>" : True } ) : <EOL> with patch . dict ( network . __salt__ , <EOL> { "<STR_LIT>" : mock } <EOL> ) : <EOL> ret . update ( { '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> '<STR_LIT>' } } ) <EOL> self . assertDictEqual ( network . managed ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> False ) , <EOL> ret ) <EOL> ret . update ( { '<STR_LIT>' : { '<STR_LIT>' : <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertDictEqual ( network . managed ( '<STR_LIT>' , '<STR_LIT>' ) , ret ) <EOL> def test_routes ( self ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> mock = MagicMock ( side_effect = [ AttributeError , False , False , "<STR_LIT:True>" , <EOL> False , False ] ) <EOL> with patch . dict ( network . __salt__ , { "<STR_LIT>" : mock } ) : <EOL> self . assertDictEqual ( network . routes ( '<STR_LIT>' ) , ret ) <EOL> mock = MagicMock ( side_effect = [ False , True , '<STR_LIT>' , True , True ] ) <EOL> with patch . dict ( network . __salt__ , { "<STR_LIT>" : mock } ) : <EOL> ret . update ( { '<STR_LIT:result>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> self . assertDictEqual ( network . routes ( '<STR_LIT>' , test = '<STR_LIT:a>' ) , ret ) <EOL> ret . update ( { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( network . routes ( '<STR_LIT>' , test = '<STR_LIT:a>' ) , ret ) <EOL> ret . update ( { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' } ) <EOL> self . assertDictEqual ( network . routes ( '<STR_LIT>' , test = '<STR_LIT:a>' ) , ret ) <EOL> mock = MagicMock ( side_effect = [ AttributeError , True ] ) <EOL> with patch . dict ( network . __salt__ , <EOL> { "<STR_LIT>" : mock } ) : <EOL> ret . update ( { '<STR_LIT>' : { '<STR_LIT>' : <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:result>' : False } ) <EOL> self . assertDictEqual ( network . routes ( '<STR_LIT>' ) , ret ) <EOL> ret . update ( { '<STR_LIT>' : { '<STR_LIT>' : <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:result>' : True } ) <EOL> self . assertDictEqual ( network . routes ( '<STR_LIT>' ) , ret ) <EOL> def test_system ( self ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> with patch . dict ( network . __opts__ , { "<STR_LIT:test>" : True } ) : <EOL> mock = MagicMock ( side_effect = [ AttributeError , False , False , '<STR_LIT>' ] ) <EOL> with patch . dict ( network . __salt__ , <EOL> { "<STR_LIT>" : mock } ) : <EOL> self . assertDictEqual ( network . system ( '<STR_LIT>' ) , ret ) <EOL> mock = MagicMock ( side_effect = [ False , True , '<STR_LIT>' ] ) <EOL> with patch . dict ( network . __salt__ , <EOL> { "<STR_LIT>" : mock } ) : <EOL> ret . update ( { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:result>' : True } ) <EOL> self . assertDictEqual ( network . system ( '<STR_LIT>' ) , ret ) <EOL> ret . update ( { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( network . system ( '<STR_LIT>' ) , ret ) <EOL> ret . update ( { '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' } ) <EOL> self . assertDictEqual ( network . system ( '<STR_LIT>' ) , ret ) <EOL> with patch . dict ( network . __opts__ , { "<STR_LIT:test>" : False } ) : <EOL> mock = MagicMock ( side_effect = [ False , False ] ) <EOL> with patch . dict ( network . __salt__ , <EOL> { "<STR_LIT>" : mock } ) : <EOL> mock = MagicMock ( side_effect = [ True , True ] ) <EOL> with patch . dict ( network . __salt__ , <EOL> { "<STR_LIT>" : mock } ) : <EOL> mock = MagicMock ( side_effect = [ AttributeError , True ] ) <EOL> with patch . dict ( network . __salt__ , <EOL> { "<STR_LIT>" : mock } ) : <EOL> ret . update ( { '<STR_LIT>' : { '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:result>' : False } ) <EOL> self . assertDictEqual ( network . system ( '<STR_LIT>' ) , ret ) <EOL> ret . update ( { '<STR_LIT>' : { '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:result>' : True } ) <EOL> self . assertDictEqual ( network . system ( '<STR_LIT>' ) , ret ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( NetworkTestCase , needs_daemon = False ) </s>
