<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> from salt . exceptions import SaltInvocationError <EOL> import json <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . states import grafana <EOL> grafana . __opts__ = { } <EOL> grafana . __salt__ = { } <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class GrafanaTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def test_dashboard_present ( self ) : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> rows = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' ] <EOL> row = [ { '<STR_LIT>' : [ { '<STR_LIT:id>' : '<STR_LIT:a>' } ] , '<STR_LIT:title>' : '<STR_LIT>' } ] <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> comt1 = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertRaises ( SaltInvocationError , grafana . dashboard_present , name , <EOL> profile = False ) <EOL> self . assertRaises ( SaltInvocationError , grafana . dashboard_present , name , <EOL> True , True ) <EOL> mock = MagicMock ( side_effect = [ { '<STR_LIT>' : True , '<STR_LIT:index>' : False } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } ] ) <EOL> mock_f = MagicMock ( side_effect = [ False , False , True , True , True , True ] ) <EOL> mock_t = MagicMock ( return_value = '<STR_LIT>' ) <EOL> mock_i = MagicMock ( return_value = False ) <EOL> source = { '<STR_LIT>' : '<STR_LIT>' } <EOL> mock_dict = MagicMock ( return_value = { '<STR_LIT>' : source } ) <EOL> with patch . dict ( grafana . __salt__ , { '<STR_LIT>' : mock , <EOL> '<STR_LIT>' : mock_f , <EOL> '<STR_LIT>' : mock_t , <EOL> '<STR_LIT>' : mock_dict , <EOL> '<STR_LIT>' : mock_i } ) : <EOL> self . assertRaises ( SaltInvocationError , grafana . dashboard_present , <EOL> name ) <EOL> with patch . dict ( grafana . __opts__ , { '<STR_LIT:test>' : True } ) : <EOL> self . assertRaises ( SaltInvocationError , grafana . dashboard_present , <EOL> name ) <EOL> comt = ( '<STR_LIT>' . format ( name ) ) <EOL> ret . update ( { '<STR_LIT>' : comt } ) <EOL> self . assertDictEqual ( grafana . dashboard_present ( name , True ) , ret ) <EOL> mock = MagicMock ( return_value = { '<STR_LIT>' : <EOL> [ { '<STR_LIT>' : '<STR_LIT:b>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' } ] } ) <EOL> with patch . object ( json , '<STR_LIT>' , mock ) : <EOL> ret . update ( { '<STR_LIT>' : comt1 , '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( grafana . dashboard_present ( name , True , <EOL> rows = row ) , <EOL> ret ) <EOL> with patch . object ( json , '<STR_LIT>' , <EOL> MagicMock ( return_value = { '<STR_LIT>' : { } } ) ) : <EOL> self . assertRaises ( SaltInvocationError , <EOL> grafana . dashboard_present , name , <EOL> rows_from_pillar = rows ) <EOL> comt = ( '<STR_LIT>' ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : True } ) <EOL> self . assertDictEqual ( grafana . dashboard_present ( name , True ) , ret ) <EOL> mock = MagicMock ( return_value = { '<STR_LIT>' : [ { '<STR_LIT>' : '<STR_LIT:b>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' } ] } ) <EOL> with patch . dict ( grafana . __opts__ , { '<STR_LIT:test>' : False } ) : <EOL> with patch . object ( json , '<STR_LIT>' , mock ) : <EOL> comt = ( '<STR_LIT>' ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : False } ) <EOL> self . assertDictEqual ( grafana . dashboard_present ( name , True , <EOL> rows = row ) , <EOL> ret ) <EOL> def test_dashboard_absent ( self ) : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> mock = MagicMock ( side_effect = [ { '<STR_LIT>' : True , '<STR_LIT:index>' : False } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } , <EOL> { '<STR_LIT>' : True , '<STR_LIT:index>' : True } ] ) <EOL> mock_f = MagicMock ( side_effect = [ True , False ] ) <EOL> with patch . dict ( grafana . __salt__ , { '<STR_LIT>' : mock , <EOL> '<STR_LIT>' : mock_f } ) : <EOL> self . assertRaises ( SaltInvocationError , grafana . dashboard_absent , <EOL> name ) <EOL> with patch . dict ( grafana . __opts__ , { '<STR_LIT:test>' : True } ) : <EOL> comt = ( '<STR_LIT>' ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : None } ) <EOL> self . assertDictEqual ( grafana . dashboard_absent ( name ) , ret ) <EOL> comt = ( '<STR_LIT>' ) <EOL> ret . update ( { '<STR_LIT>' : comt , '<STR_LIT:result>' : True } ) <EOL> self . assertDictEqual ( grafana . dashboard_absent ( name ) , ret ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( GrafanaTestCase , needs_daemon = False ) </s>
