Skip to content

Commit 7463af7

Browse files
author
Dan Xie
committed
update 8
1 parent ca53cb1 commit 7463af7

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/china-support/china-forward-function/tests/test_handler.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
Tests for the AWS Lambda handler that forwards events to Step Functions.
33
"""
44
import os
5+
import importlib
56
from unittest.mock import patch, MagicMock
67

78
import pytest
89
import handler
910

11+
# pylint: disable=redefined-outer-name,no-member,unused-argument
1012

1113
@pytest.fixture
1214
def mock_env_variables(aws_settings):
@@ -40,7 +42,11 @@ def mock_boto3_session():
4042
# Patch boto3.session.Session to use our mock constructor
4143
with patch("boto3.session.Session", mock_session_constructor):
4244
# Yield both the session constructor and client mocks
43-
yield {"session_constructor": mock_session_constructor, "session": mock_session, "client": mock_client}
45+
yield {
46+
"session_constructor": mock_session_constructor,
47+
"session": mock_session,
48+
"client": mock_client
49+
}
4450

4551

4652
@pytest.fixture
@@ -58,7 +64,11 @@ class TestLambdaHandler:
5864
"""Tests for the lambda_handler function."""
5965

6066
def test_lambda_handler_with_organizations_event(
61-
self, mock_env_variables, mock_boto3_session, mock_stepfunction, aws_settings # pylint: disable=unused-argument
67+
self,
68+
mock_env_variables,
69+
mock_boto3_session,
70+
mock_stepfunction,
71+
aws_settings
6272
):
6373
"""Test handling of an AWS Organizations event."""
6474
region = aws_settings["region"]
@@ -86,7 +96,7 @@ def test_lambda_handler_with_organizations_event(
8696
)
8797

8898
def test_lambda_handler_with_non_organizations_event(
89-
self, mock_env_variables, mock_boto3_session, mock_stepfunction # pylint: disable=unused-argument
99+
self, mock_env_variables, mock_boto3_session, mock_stepfunction
90100
):
91101
"""Test handling of a non-AWS Organizations event."""
92102
event = {
@@ -100,7 +110,12 @@ def test_lambda_handler_with_non_organizations_event(
100110
handler.Stepfunction.assert_not_called()
101111
mock_stepfunction.invoke_sfn_execution.assert_not_called()
102112

103-
def test_lambda_handler_with_missing_source(self, mock_env_variables, mock_boto3_session, mock_stepfunction): # pylint: disable=unused-argument
113+
def test_lambda_handler_with_missing_source(
114+
self,
115+
mock_env_variables,
116+
mock_boto3_session,
117+
mock_stepfunction
118+
):
104119
"""Test handling of an event missing the source field."""
105120
event = {"detail-type": "Some Event", "detail": {}}
106121

@@ -118,8 +133,5 @@ def test_sfn_name_extraction(aws_settings):
118133
partition = aws_settings["partition"]
119134
sfn_arn = f"arn:{partition}:states:{region}:123456789012:stateMachine:{sfn_name}"
120135
with patch.dict(os.environ, {"SFN_ARN": sfn_arn}):
121-
# Re-import to get the updated SFN_ARN value
122-
import importlib
123-
124136
importlib.reload(handler)
125137
assert handler.sfn_name == sfn_name

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/china-support/tests/test_create_s3_cn.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"""
22
s3 bucket creation script
33
"""
4-
5-
import pytest
64
from unittest.mock import patch, MagicMock
75

8-
# Import the module to test
6+
import pytest
97
import create_s3_cn
108

9+
# pylint: disable=redefined-outer-name,no-member,unused-argument
1110

1211
@pytest.fixture
1312
def mock_env_vars():
@@ -46,7 +45,7 @@ def mock_logger():
4645
yield mock_logger
4746

4847

49-
def test_create_s3_bucket_china(mock_env_vars, mock_cloudformation, mock_logger): # pylint: disable=unused-argument
48+
def test_create_s3_bucket_china(mock_env_vars, mock_cloudformation, mock_logger):
5049
"""Test creating an S3 bucket in China region."""
5150
# Arrange
5251
bucket_name = "adf-china-bootstrap-cn-northwest-1-123456789012"
@@ -81,7 +80,7 @@ def test_create_s3_bucket_china(mock_env_vars, mock_cloudformation, mock_logger)
8180
mock_logger.info.assert_called_with("Deploy S3 bucket %s...", bucket_name)
8281

8382

84-
def test_create_s3_bucket_exception(mock_env_vars, mock_cloudformation, mock_logger): # pylint: disable=unused-argument
83+
def test_create_s3_bucket_exception(mock_env_vars, mock_cloudformation, mock_logger):
8584
"""Test exception handling when creating an S3 bucket fails."""
8685
# Arrange
8786
bucket_name = "adf-china-bootstrap-cn-northwest-1-123456789012"
@@ -96,7 +95,7 @@ def test_create_s3_bucket_exception(mock_env_vars, mock_cloudformation, mock_log
9695
assert "Failed to process _create_s3_bucket" in mock_logger.error.call_args[0][0]
9796

9897

99-
def test_main_function(mock_env_vars, monkeypatch): # pylint: disable=unused-argument
98+
def test_main_function(mock_env_vars, monkeypatch):
10099
"""Test the main function calls _create_s3_bucket with correct bucket name."""
101100
# Arrange
102101
mock_create_bucket = MagicMock()
@@ -112,7 +111,7 @@ def test_main_function(mock_env_vars, monkeypatch): # pylint: disable=unused-arg
112111
mock_create_bucket.assert_called_once_with(expected_bucket_name)
113112

114113

115-
def test_cloudformation_template_path(mock_env_vars, mock_cloudformation): # pylint: disable=unused-argument
114+
def test_cloudformation_template_path(mock_env_vars, mock_cloudformation):
116115
"""Test the CloudFormation template path is correct."""
117116
# Arrange
118117
bucket_name = "test-bucket"

0 commit comments

Comments
 (0)