Add support for glob matching to entity filters (#36913)

* Added GLOB capability to entityfilter and every place that uses it. All existing tests are passing

* added tests for components affected by glob change

* fixed flake8 error

* mocking the correct listener

* mocking correct bus method in azure test

* tests passing in 3.7 and 3.8

* fixed formatting issue from rebase/conflict

* Checking against glob patterns in more performant way

* perf improvments and reverted unnecessarily adjusted tests

* added new benchmark test around filters

* no longer using get with default in entityfilter

* changed filter name and removed logbook from filter benchmark

* simplified benchmark tests from feedback

* fixed apache tests and returned include exclude schemas to normal

* fixed azure event hub tests to properly go through component logic

* fixed azure test and clean up for other tests

* renaming test files to match standard

* merged mqtt statestream test changes with base

* removed dependency on recorder filter schema from history

* fixed recorder tests after merge and a bunch of lint errors
This commit is contained in:
mdegat01 2020-06-23 21:02:29 -04:00 committed by GitHub
parent a1ac1fb091
commit 6c7355785a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1832 additions and 278 deletions

View file

@ -58,6 +58,7 @@ class TestSplunk(unittest.TestCase):
def _setup(self, mock_requests):
"""Test the setup."""
# pylint: disable=attribute-defined-outside-init
self.mock_post = mock_requests.post
self.mock_request_exception = Exception
mock_requests.exceptions.RequestException = self.mock_request_exception
@ -115,7 +116,7 @@ class TestSplunk(unittest.TestCase):
)
self.mock_post.reset_mock()
def _setup_with_filter(self):
def _setup_with_filter(self, addl_filters=None):
"""Test the setup."""
config = {
"splunk": {
@ -128,12 +129,15 @@ class TestSplunk(unittest.TestCase):
},
}
}
if addl_filters:
config["splunk"]["filter"].update(addl_filters)
setup_component(self.hass, splunk.DOMAIN, config)
@mock.patch.object(splunk, "post_request")
def test_splunk_entityfilter(self, mock_requests):
"""Test event listener."""
# pylint: disable=no-member
self._setup_with_filter()
testdata = [
@ -152,3 +156,27 @@ class TestSplunk(unittest.TestCase):
assert splunk.post_request.called
splunk.post_request.reset_mock()
@mock.patch.object(splunk, "post_request")
def test_splunk_entityfilter_with_glob_filter(self, mock_requests):
"""Test event listener."""
# pylint: disable=no-member
self._setup_with_filter({"exclude_entity_globs": ["*.skip_*"]})
testdata = [
{"entity_id": "other_domain.other_entity", "filter_expected": False},
{"entity_id": "other_domain.excluded_entity", "filter_expected": True},
{"entity_id": "excluded_domain.other_entity", "filter_expected": True},
{"entity_id": "test.skip_me", "filter_expected": True},
]
for test in testdata:
mock_state_change_event(self.hass, State(test["entity_id"], "on"))
self.hass.block_till_done()
if test["filter_expected"]:
assert not splunk.post_request.called
else:
assert splunk.post_request.called
splunk.post_request.reset_mock()