Skip to content

Commit

Permalink
updates to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandeivert committed Apr 9, 2020
1 parent 146edd0 commit 706e3a3
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 8 deletions.
1 change: 1 addition & 0 deletions tests/unit/helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def basic_streamalert_config():
}
}
},
'scheduled_queries': {},
'threat_intel': {
'dynamodb_table_name': 'table_name',
'enabled': False,
Expand Down
57 changes: 57 additions & 0 deletions tests/unit/streamalert_cli/manage_lambda/test_deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Copyright 2017-present Airbnb, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=no-self-use,protected-access
import unittest

from mock import patch
from nose.tools import assert_equal

from streamalert_cli.manage_lambda import deploy
from tests.unit.helpers.config import basic_streamalert_config


class DeployTest(unittest.TestCase):
"""DeployTest class for testing deployment functions"""

def test_lambda_terraform_targets(self):
"""CLI - Deploy, Lambda Terraform Targets"""
config = basic_streamalert_config()
functions = ['rule', 'classifier']
clusters = ['prod']
result = deploy._lambda_terraform_targets(config, functions, clusters)
expected_result = {
'module.rules_engine_iam',
'module.rules_engine_lambda',
'module.classifier_prod_iam',
'module.classifier_prod_lambda',
}
assert_equal(result, expected_result)

@patch('logging.Logger.error')
def test_lambda_terraform_targets_invalid_target(self, log_mock):
"""CLI - Deploy, Lambda Terraform Targets, Invalid Target"""
config = basic_streamalert_config()

# The scheduled_queries function is not enabled
functions = ['scheduled_queries']
clusters = []
result = deploy._lambda_terraform_targets(config, functions, clusters)

assert_equal(result, set())
log_mock.assert_called_with(
'Function is not enabled and will be ignored: %s',
'scheduled_queries'
)
16 changes: 15 additions & 1 deletion tests/unit/streamalert_cli/manage_lambda/test_rollback.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
"""Test ./manage.py lambda rollback functionality."""
"""
Copyright 2017-present Airbnb, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=no-self-use,protected-access
import unittest

Expand Down
2 changes: 0 additions & 2 deletions tests/unit/streamalert_cli/terraform/test_alert_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def test_generate_all_options(self):
'errors_alarm_evaluation_periods': 1,
'errors_alarm_period_secs': 2,
'errors_alarm_threshold': 3,
'filename': 'alert_processor.zip',
'function_name': 'unit-test_streamalert_alert_processor',
'handler': 'streamalert.alert_processor.main.handler',
'log_retention_days': 7,
Expand Down Expand Up @@ -121,7 +120,6 @@ def test_generate_minimal_options(self):
'LOGGER_LEVEL': 'info'
},
'tags': {},
'filename': 'alert_processor.zip',
'function_name': 'unit-test_streamalert_alert_processor',
'handler': 'streamalert.alert_processor.main.handler',
'memory_size_mb': 128,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/streamalert_cli/terraform/test_athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_generate_athena():
'tags': {
'Subcomponent': 'AthenaPartitioner'
},
'filename': 'athena_partitioner.zip',
'function_name': 'unit-test_streamalert_athena_partitioner',
'handler': 'streamalert.athena_partitioner.main.handler',
'memory_size_mb': 128,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def test_generate_classifier(self):
'errors_alarm_evaluation_periods': 1,
'errors_alarm_period_secs': 120,
'errors_alarm_threshold': 0,
'filename': 'classifier.zip',
'function_name': 'unit-test_test_streamalert_classifier',
'handler': 'streamalert.classifier.main.handler',
'log_retention_days': 14,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def test_generate_rules_engine(self):
'errors_alarm_evaluation_periods': 1,
'errors_alarm_period_secs': 120,
'errors_alarm_threshold': 0,
'filename': 'rules_engine.zip',
'function_name': 'unit-test_streamalert_rules_engine',
'handler': 'streamalert.rules_engine.main.handler',
'log_retention_days': 14,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def test_generate(self):
'errors_alarm_evaluation_periods': 1,
'errors_alarm_period_secs': 2,
'errors_alarm_threshold': 3,
'filename': 'rule_promotion.zip',
'function_name': 'unit-test_streamalert_rule_promotion',
'handler': 'streamalert.rule_promotion.main.handler',
'log_retention_days': 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def test_generate_scheduled_queries():
'${module.kinesis_firehose_setup.data_bucket_name}',
'bucket',
],
'lambda_filename': 'scheduled_queries.zip',
'lambda_handler': 'streamalert.scheduled_queries.main.handler',
'query_packs': [
{
Expand Down

0 comments on commit 706e3a3

Please sign in to comment.