From 49b1643ff0709b0d54d3490e230d2c082652fb0c Mon Sep 17 00:00:00 2001 From: Georgi Kirichkov Date: Sat, 15 Oct 2016 07:10:04 +0300 Subject: [PATCH] Relaxes the configuration options for influxdb (#3869) * Relaxes the configuration options for influxdb By default influxdb allows unauthenticated access Home Assistant required at least username and password to be present to properly submit data to influxdb * Removes unused import of 'copy' The copy module was used only in the removed test case responsible for testing the missing keys * Updates InfluxDB config schema to require user and password Current InfluxDB (v 1.0) can work without any authentication, but when authentication is enabled both username and password should be set. * Removes extra white space in test_influxdb.py --- homeassistant/components/influxdb.py | 4 ++-- tests/components/test_influxdb.py | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/influxdb.py b/homeassistant/components/influxdb.py index 6bac1fa7cfb..420781bcb74 100644 --- a/homeassistant/components/influxdb.py +++ b/homeassistant/components/influxdb.py @@ -33,8 +33,8 @@ TIMEOUT = 5 CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string, - vol.Required(CONF_USERNAME): cv.string, - vol.Required(CONF_PASSWORD): cv.string, + vol.Inclusive(CONF_USERNAME, 'authentication'): cv.string, + vol.Inclusive(CONF_PASSWORD, 'authentication'): cv.string, vol.Optional(CONF_BLACKLIST, default=[]): vol.All(cv.ensure_list, [cv.entity_id]), vol.Optional(CONF_DB_NAME, default=DEFAULT_DATABASE): cv.string, diff --git a/tests/components/test_influxdb.py b/tests/components/test_influxdb.py index 3210bf0db9f..3e4e6e0ad16 100644 --- a/tests/components/test_influxdb.py +++ b/tests/components/test_influxdb.py @@ -1,5 +1,4 @@ """The tests for the InfluxDB component.""" -import copy import unittest from unittest import mock @@ -53,18 +52,23 @@ class TestInfluxDB(unittest.TestCase): self.assertEqual(EVENT_STATE_CHANGED, self.hass.bus.listen.call_args_list[0][0][0]) - def test_setup_missing_keys(self, mock_client): - """Test the setup with missing keys.""" + def test_setup_minimal_config(self, mock_client): + """Tests the setup with minimal configuration.""" + config = { + 'influxdb': {} + } + + assert setup_component(self.hass, influxdb.DOMAIN, config) + + def test_setup_missing_password(self, mock_client): + """Test the setup with existing username and missing password.""" config = { 'influxdb': { - 'username': 'user', - 'password': 'pass', + 'username': 'user' } } - for missing in config['influxdb'].keys(): - config_copy = copy.deepcopy(config) - del config_copy['influxdb'][missing] - assert not setup_component(self.hass, influxdb.DOMAIN, config_copy) + + assert not setup_component(self.hass, influxdb.DOMAIN, config) def test_setup_query_fail(self, mock_client): """Test the setup for query failures."""