diff --git a/tests/unit/helpers/config.py b/tests/unit/helpers/config.py index f88cb29cd..9e7bf0362 100644 --- a/tests/unit/helpers/config.py +++ b/tests/unit/helpers/config.py @@ -57,6 +57,7 @@ def basic_streamalert_config(): } } }, + 'scheduled_queries': {}, 'threat_intel': { 'dynamodb_table_name': 'table_name', 'enabled': False, diff --git a/tests/unit/streamalert_cli/manage_lambda/test_deploy.py b/tests/unit/streamalert_cli/manage_lambda/test_deploy.py new file mode 100644 index 000000000..7923df4f9 --- /dev/null +++ b/tests/unit/streamalert_cli/manage_lambda/test_deploy.py @@ -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' + ) diff --git a/tests/unit/streamalert_cli/manage_lambda/test_rollback.py b/tests/unit/streamalert_cli/manage_lambda/test_rollback.py index aad76e527..a440e5bfb 100644 --- a/tests/unit/streamalert_cli/manage_lambda/test_rollback.py +++ b/tests/unit/streamalert_cli/manage_lambda/test_rollback.py @@ -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 diff --git a/tests/unit/streamalert_cli/terraform/test_alert_processor.py b/tests/unit/streamalert_cli/terraform/test_alert_processor.py index 1c46ca25c..b4fe8955c 100644 --- a/tests/unit/streamalert_cli/terraform/test_alert_processor.py +++ b/tests/unit/streamalert_cli/terraform/test_alert_processor.py @@ -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, @@ -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, diff --git a/tests/unit/streamalert_cli/terraform/test_athena.py b/tests/unit/streamalert_cli/terraform/test_athena.py index d71bc8724..aab9c187d 100644 --- a/tests/unit/streamalert_cli/terraform/test_athena.py +++ b/tests/unit/streamalert_cli/terraform/test_athena.py @@ -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, diff --git a/tests/unit/streamalert_cli/terraform/test_generate_classifier.py b/tests/unit/streamalert_cli/terraform/test_generate_classifier.py index c5e44ba73..bc610ee6c 100644 --- a/tests/unit/streamalert_cli/terraform/test_generate_classifier.py +++ b/tests/unit/streamalert_cli/terraform/test_generate_classifier.py @@ -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, diff --git a/tests/unit/streamalert_cli/terraform/test_generate_rules_engine.py b/tests/unit/streamalert_cli/terraform/test_generate_rules_engine.py index 921e55c60..07e8e69be 100644 --- a/tests/unit/streamalert_cli/terraform/test_generate_rules_engine.py +++ b/tests/unit/streamalert_cli/terraform/test_generate_rules_engine.py @@ -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, diff --git a/tests/unit/streamalert_cli/terraform/test_rule_promotion.py b/tests/unit/streamalert_cli/terraform/test_rule_promotion.py index 01f2cf49e..edaf59926 100644 --- a/tests/unit/streamalert_cli/terraform/test_rule_promotion.py +++ b/tests/unit/streamalert_cli/terraform/test_rule_promotion.py @@ -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, diff --git a/tests/unit/streamalert_cli/terraform/test_scheduled_queries.py b/tests/unit/streamalert_cli/terraform/test_scheduled_queries.py index 9913702d9..c2b70077a 100644 --- a/tests/unit/streamalert_cli/terraform/test_scheduled_queries.py +++ b/tests/unit/streamalert_cli/terraform/test_scheduled_queries.py @@ -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': [ {