Example #1
0
    def test_invalid_query(self):
        """Test the SQL sensor for invalid queries."""
        with pytest.raises(vol.Invalid):
            validate_sql_select("DROP TABLE *")

        config = {
            'sensor': {
                'platform':
                'sql',
                'db_url':
                'sqlite://',
                'queries': [{
                    'name': 'count_tables',
                    'query': 'SELECT * value FROM sqlite_master;',
                    'column': 'value',
                }]
            }
        }

        assert setup_component(self.hass, 'sensor', config)

        state = self.hass.states.get('sensor.count_tables')
        assert state.state == STATE_UNKNOWN
Example #2
0
    def test_invalid_query(self):
        """Test the SQL sensor for invalid queries."""
        with pytest.raises(vol.Invalid):
            validate_sql_select("DROP TABLE *")

        config = {
            "sensor": {
                "platform":
                "sql",
                "db_url":
                "sqlite://",
                "queries": [{
                    "name": "count_tables",
                    "query": "SELECT * value FROM sqlite_master;",
                    "column": "value",
                }],
            }
        }

        assert setup_component(self.hass, "sensor", config)

        state = self.hass.states.get("sensor.count_tables")
        assert state.state == STATE_UNKNOWN
Example #3
0
async def test_invalid_query(hass: HomeAssistant) -> None:
    """Test the SQL sensor for invalid queries."""
    with pytest.raises(vol.Invalid):
        validate_sql_select("DROP TABLE *")

    config = {
        "sensor": {
            "platform": "sql",
            "db_url": "sqlite://",
            "queries": [
                {
                    "name": "count_tables",
                    "query": "SELECT * value FROM sqlite_master;",
                    "column": "value",
                }
            ],
        }
    }

    assert await async_setup_component(hass, "sensor", config)
    await hass.async_block_till_done()

    state = hass.states.get("sensor.count_tables")
    assert state.state == STATE_UNKNOWN