SQL sensor (#12142)
* Initial Commit * Passed all checks * Make DB_URL required * addresses review comments from @fabaff * unused variable
This commit is contained in:
parent
d0ffb1bc52
commit
0300229085
4 changed files with 184 additions and 0 deletions
37
tests/components/sensor/test_sql.py
Normal file
37
tests/components/sensor/test_sql.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
"""The test for the sql sensor platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestSQLSensor(unittest.TestCase):
|
||||
"""Test the SQL sensor."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_query(self):
|
||||
"""Test the SQL sensor."""
|
||||
config = {
|
||||
'sensor': {
|
||||
'platform': 'sql',
|
||||
'db_url': 'sqlite://',
|
||||
'queries': [{
|
||||
'name': 'count_tables',
|
||||
'query': 'SELECT count(*) value FROM sqlite_master;',
|
||||
'column': 'value',
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
assert setup_component(self.hass, 'sensor', config)
|
||||
|
||||
state = self.hass.states.get('sensor.count_tables')
|
||||
self.assertEqual(state.state, '0')
|
Loading…
Add table
Add a link
Reference in a new issue