From 59fe3ff0c9a1d121982c03a9f0710e9971ab3efa Mon Sep 17 00:00:00 2001 From: Ryan Deivert Date: Wed, 3 Jan 2018 14:00:10 -0800 Subject: [PATCH] [tests] adding unit test for log count --- .../test_outputs/test_pagerduty.py | 2 +- .../stream_alert_rule_processor/test_handler.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/unit/stream_alert_alert_processor/test_outputs/test_pagerduty.py b/tests/unit/stream_alert_alert_processor/test_outputs/test_pagerduty.py index 9cf64e317..4308c5b94 100644 --- a/tests/unit/stream_alert_alert_processor/test_outputs/test_pagerduty.py +++ b/tests/unit/stream_alert_alert_processor/test_outputs/test_pagerduty.py @@ -199,7 +199,7 @@ def test_check_exists_get_id_fail(self, get_mock): @patch('requests.get') def test_check_exists_no_get_id(self, get_mock): - """Check Exists No Get Id - PagerDutyIncidentOutput""" + """PagerDutyIncidentOutput - Check Exists No Get Id""" # /check get_mock.return_value.status_code = 200 json_check = {'check': [{'id': 'checked_id'}]} diff --git a/tests/unit/stream_alert_rule_processor/test_handler.py b/tests/unit/stream_alert_rule_processor/test_handler.py index e7794e5e9..979a7c76f 100644 --- a/tests/unit/stream_alert_rule_processor/test_handler.py +++ b/tests/unit/stream_alert_rule_processor/test_handler.py @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. """ -# pylint: disable=protected-access +# pylint: disable=protected-access,attribute-defined-outside-init import base64 import json import logging @@ -45,9 +45,6 @@ class TestStreamAlert(object): """Test class for StreamAlert class""" - def __init__(self): - self.__sa_handler = None - @patch('stream_alert.rule_processor.handler.load_config', lambda: load_config('tests/unit/conf/')) def setup(self): @@ -131,6 +128,14 @@ def test_run_with_alert(self, extract_mock, rules_mock): assert_true(passed) + @patch('stream_alert.rule_processor.handler.StreamClassifier.extract_service_and_entity') + def test_run_alert_count(self, extract_mock): + """StreamAlert Class - Run, Check Count With 4 Logs""" + count = 4 + extract_mock.return_value = ('kinesis', 'unit_test_default_stream') + self.__sa_handler.run(get_valid_event(count)) + assert_equal(self.__sa_handler._processed_record_count, count) + @patch('logging.Logger.debug') @patch('stream_alert.rule_processor.handler.StreamClassifier.extract_service_and_entity') def test_run_no_alerts(self, extract_mock, log_mock):