@@ -30,8 +30,9 @@ def test_client_initialization_region_mismatch():
30
30
"""Test client initialization with region mismatch warning."""
31
31
32
32
with patch ("boto3.client" ) as mock_boto_client :
33
+ # First test - environment variable takes precedence
33
34
with patch ("boto3.Session" ) as mock_session :
34
- # Mock the session instance
35
+ # Mock the session instance to simulate AWS_REGION=us-east-1
35
36
mock_session_instance = MagicMock ()
36
37
mock_session_instance .region_name = "us-east-1"
37
38
mock_session .return_value = mock_session_instance
@@ -41,17 +42,23 @@ def test_client_initialization_region_mismatch():
41
42
mock_client_instance .meta .region_name = "us-east-1"
42
43
mock_boto_client .return_value = mock_client_instance
43
44
44
- # When region_name is not provided, it should use the boto3 default
45
- client1 = MemoryClient ()
46
- assert client1 .region_name == "us-east-1"
45
+ # When region_name is provided, environment variable should still take precedence
46
+ client1 = MemoryClient (region_name = "us-west-2" )
47
+ assert client1 .region_name == "us-east-1" # Environment wins over explicit param
47
48
48
- # Reset the mock to test with a specified region
49
- mock_boto_client .reset_mock ()
49
+ # Second test - no environment variable, explicit param is used
50
+ with patch ("boto3.Session" ) as mock_session :
51
+ # Mock the session instance to simulate no AWS_REGION set
52
+ mock_session_instance = MagicMock ()
53
+ mock_session_instance .region_name = None
54
+ mock_session .return_value = mock_session_instance
55
+
56
+ # Mock the boto client
50
57
mock_client_instance = MagicMock ()
51
58
mock_client_instance .meta .region_name = "us-west-2"
52
59
mock_boto_client .return_value = mock_client_instance
53
60
54
- # When region_name is provided, it should use that value
61
+ # When AWS_REGION is not set, explicitly provided region should be used
55
62
client2 = MemoryClient (region_name = "us-west-2" )
56
63
assert client2 .region_name == "us-west-2"
57
64
0 commit comments