<s> """<STR_LIT>""" <EOL> import unittest <EOL> from unittest import mock <EOL> import homeassistant . components . splunk as splunk <EOL> from homeassistant . const import STATE_ON , STATE_OFF , EVENT_STATE_CHANGED <EOL> class TestSplunk ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_setup_config_full ( self ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:host>' : '<STR_LIT:host>' , <EOL> '<STR_LIT:port>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:False>' , <EOL> } <EOL> } <EOL> hass = mock . MagicMock ( ) <EOL> self . assertTrue ( splunk . setup ( hass , config ) ) <EOL> self . assertTrue ( hass . bus . listen . called ) <EOL> self . assertEqual ( EVENT_STATE_CHANGED , <EOL> hass . bus . listen . call_args_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> def test_setup_config_defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:host>' : '<STR_LIT:host>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> hass = mock . MagicMock ( ) <EOL> self . assertTrue ( splunk . setup ( hass , config ) ) <EOL> self . assertTrue ( hass . bus . listen . called ) <EOL> self . assertEqual ( EVENT_STATE_CHANGED , <EOL> hass . bus . listen . call_args_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> def _setup ( self , mock_requests ) : <EOL> """<STR_LIT>""" <EOL> self . mock_post = mock_requests . post <EOL> self . mock_request_exception = Exception <EOL> mock_requests . exceptions . RequestException = self . mock_request_exception <EOL> config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:host>' : '<STR_LIT:host>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> self . hass = mock . MagicMock ( ) <EOL> splunk . setup ( self . hass , config ) <EOL> self . handler_method = self . hass . bus . listen . call_args_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> @ mock . patch . object ( splunk , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_event_listener ( self , mock_dump , mock_requests ) : <EOL> """<STR_LIT>""" <EOL> mock_dump . side_effect = lambda x : x <EOL> self . _setup ( mock_requests ) <EOL> valid = { '<STR_LIT:1>' : <NUM_LIT:1> , <EOL> '<STR_LIT:1.0>' : <NUM_LIT:1.0> , <EOL> STATE_ON : <NUM_LIT:1> , <EOL> STATE_OFF : <NUM_LIT:0> , <EOL> '<STR_LIT:foo>' : '<STR_LIT:foo>' } <EOL> for in_ , out in valid . items ( ) : <EOL> state = mock . MagicMock ( state = in_ , <EOL> domain = '<STR_LIT>' , <EOL> object_id = '<STR_LIT>' , <EOL> attributes = { } ) <EOL> event = mock . MagicMock ( data = { '<STR_LIT>' : state } , <EOL> time_fired = <NUM_LIT> ) <EOL> body = [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:time>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : out , <EOL> } ] <EOL> payload = { '<STR_LIT:host>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : body } <EOL> self . handler_method ( event ) <EOL> self . mock_post . assert_called_once_with ( <EOL> payload [ '<STR_LIT:host>' ] , data = payload , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . mock_post . reset_mock ( ) </s>
