From 7892c52d11c46c6f7079e97dd8a1f9a8eeddb079 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 4 May 2023 08:15:08 -0700 Subject: [PATCH] fix tests --- app/clients/cloudwatch/aws_cloudwatch.py | 2 +- tests/app/clients/test_aws_cloudwatch.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/clients/cloudwatch/aws_cloudwatch.py b/app/clients/cloudwatch/aws_cloudwatch.py index 847b39bf9..6d5498827 100644 --- a/app/clients/cloudwatch/aws_cloudwatch.py +++ b/app/clients/cloudwatch/aws_cloudwatch.py @@ -59,7 +59,7 @@ class AwsCloudwatchClient(CloudwatchClient): return all_log_events def check_sms(self, message_id, notification_id): - # TODO presumably there is a better way to get the account number + # TODO presumably there is a better way to get the aws account number account_number = os.getenv("SES_DOMAIN_ARN") account_number = account_number.replace('arn:aws:ses:us-west-2:', '') account_number = account_number.split(":") diff --git a/tests/app/clients/test_aws_cloudwatch.py b/tests/app/clients/test_aws_cloudwatch.py index 78faa69ea..38ca50243 100644 --- a/tests/app/clients/test_aws_cloudwatch.py +++ b/tests/app/clients/test_aws_cloudwatch.py @@ -6,6 +6,10 @@ from app import aws_cloudwatch_client def test_check_sms_no_event_error_condition(notify_api, mocker): boto_mock = mocker.patch.object(aws_cloudwatch_client, '_client', create=True) + # TODO + # we do this to get the AWS account number, and it seems like unit tests locally have + # access to the env variables but when we push the PR they do not. Is there a better way to get it? + mocker.patch.dict('os.environ', {"SES_DOMAIN_ARN": "1111:"}) message_id = 'aaa' notification_id = 'bbb' boto_mock.filter_log_events.return_value = [] @@ -49,6 +53,8 @@ def test_check_sms_success(notify_api, mocker): aws_cloudwatch_client.init_app(current_app) boto_mock = mocker.patch.object(aws_cloudwatch_client, '_client', create=True) boto_mock.filter_log_events.side_effect = side_effect + mocker.patch.dict('os.environ', {"SES_DOMAIN_ARN": "1111:"}) + message_id = 'succeed' notification_id = 'ccc' with notify_api.app_context(): @@ -66,6 +72,8 @@ def test_check_sms_failure(notify_api, mocker): aws_cloudwatch_client.init_app(current_app) boto_mock = mocker.patch.object(aws_cloudwatch_client, '_client', create=True) boto_mock.filter_log_events.side_effect = side_effect + mocker.patch.dict('os.environ', {"SES_DOMAIN_ARN": "1111:"}) + message_id = 'fail' notification_id = 'bbb' with notify_api.app_context():