def _setup(self): """Setup the client.""" config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', 'blacklist': ['fake.blacklisted'] } } influxdb.setup(self.hass, config) self.handler_method = self.hass.bus.listen.call_args_list[0][0][1]
def _setup(self, mock_influx): self.mock_client = mock_influx.return_value config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', } } self.hass = mock.MagicMock() influxdb.setup(self.hass, config) self.handler_method = self.hass.bus.listen.call_args_list[0][0][1]
def test_setup_query_fail(self, mock_client): """Test the setup for query failures.""" config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', } } mock_client.return_value.query.side_effect = \ influx_client.exceptions.InfluxDBClientError('fake') self.assertFalse(influxdb.setup(self.hass, config))
def test_setup_query_fail(self, mock_client): config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', } } hass = mock.MagicMock() mock_client.return_value.query.side_effect = \ influx_client.exceptions.InfluxDBClientError('fake') self.assertFalse(influxdb.setup(hass, config))
def test_setup_missing_keys(self, mock_client): config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', } } hass = mock.MagicMock() for missing in config['influxdb'].keys(): config_copy = copy.deepcopy(config) del config_copy['influxdb'][missing] self.assertFalse(influxdb.setup(hass, config_copy))
def test_setup_config_defaults(self, mock_client): config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', } } hass = mock.MagicMock() self.assertTrue(influxdb.setup(hass, config)) self.assertTrue(hass.bus.listen.called) self.assertEqual(EVENT_STATE_CHANGED, hass.bus.listen.call_args_list[0][0][0])
def test_setup_missing_keys(self, mock_client): """Test the setup with missing keys.""" config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', } } for missing in config['influxdb'].keys(): config_copy = copy.deepcopy(config) del config_copy['influxdb'][missing] self.assertFalse(influxdb.setup(self.hass, config_copy))
def test_setup_config_defaults(self, mock_client): """Test the setup with default configuration.""" config = { 'influxdb': { 'host': 'host', 'username': '******', 'password': '******', } } self.assertTrue(influxdb.setup(self.hass, config)) self.assertTrue(self.hass.bus.listen.called) self.assertEqual(EVENT_STATE_CHANGED, self.hass.bus.listen.call_args_list[0][0][0])
def test_setup_config_full(self, mock_client): config = { 'influxdb': { 'host': 'host', 'port': 123, 'database': 'db', 'username': '******', 'password': '******', 'ssl': 'False', 'verify_ssl': 'False', } } hass = mock.MagicMock() self.assertTrue(influxdb.setup(hass, config)) self.assertTrue(hass.bus.listen.called) self.assertEqual(EVENT_STATE_CHANGED, hass.bus.listen.call_args_list[0][0][0]) self.assertTrue(mock_client.return_value.query.called)
def test_setup_config_full(self, mock_client): """Test the setup with full configuration.""" config = { 'influxdb': { 'host': 'host', 'port': 123, 'database': 'db', 'username': '******', 'password': '******', 'ssl': 'False', 'verify_ssl': 'False', } } self.assertTrue(influxdb.setup(self.hass, config)) self.assertTrue(self.hass.bus.listen.called) self.assertEqual(EVENT_STATE_CHANGED, self.hass.bus.listen.call_args_list[0][0][0]) self.assertTrue(mock_client.return_value.query.called)