'Test event listener.'

@mock.patch.object(splunk, 'requests')
@mock.patch('json.dumps')
def test_event_listener(self, mock_dump, mock_requests):

    mock_dump.side_effect = (lambda x: x)
    self._setup(mock_requests)
    valid = {'1': 1, '1.0': 1.0, STATE_ON: 1, STATE_OFF: 0, 'foo': 'foo'}
    for (in_, out) in valid.items():
        state = mock.MagicMock(state=in_, domain='fake', object_id='entity', attributes={})
        event = mock.MagicMock(data={'new_state': state}, time_fired=12345)
        body = [{'domain': 'fake', 'entity_id': 'entity', 'attributes': {}, 'time': '12345', 'value': out, 'host': 'HASS'}]
        payload = {'host': 'http://host:8088/services/collector/event', 'event': body}
        self.handler_method(event)
        self.assertEqual(self.mock_post.call_count, 1)
        self.assertEqual(self.mock_post.call_args, mock.call(payload['host'], data=payload, headers={'Authorization': 'Splunk    secret'}, timeout=10))
        self.mock_post.reset_mock()
