8
8
9
9
10
10
def test_s3_client_with_storage_options (monkeypatch ):
11
- boto3 = mock .MagicMock ()
11
+ boto3_session = mock .MagicMock ()
12
+ boto3 = mock .MagicMock (Session = boto3_session )
12
13
monkeypatch .setattr (client , "boto3" , boto3 )
13
14
14
15
botocore = mock .MagicMock ()
15
16
monkeypatch .setattr (client , "botocore" , botocore )
16
17
18
+ # Create S3Client with storage options
17
19
storage_options = {
18
20
"region_name" : "us-west-2" ,
19
21
"endpoint_url" : "https://custom.endpoint" ,
@@ -23,24 +25,27 @@ def test_s3_client_with_storage_options(monkeypatch):
23
25
24
26
assert s3_client .client
25
27
26
- boto3 .client .assert_called_with (
28
+ boto3_session () .client .assert_called_with (
27
29
"s3" ,
28
30
region_name = "us-west-2" ,
29
31
endpoint_url = "https://custom.endpoint" ,
30
32
config = botocore .config .Config (retries = {"max_attempts" : 100 }),
31
33
)
32
34
35
+ # Create S3Client without storage options
33
36
s3_client = client .S3Client ()
34
-
35
37
assert s3_client .client
36
38
37
- boto3 .client .assert_called_with (
38
- "s3" , config = botocore .config .Config (retries = {"max_attempts" : 1000 , "mode" : "adaptive" })
39
+ # Verify that boto3.Session().client was called with the default parameters
40
+ boto3_session ().client .assert_called_with (
41
+ "s3" ,
42
+ config = botocore .config .Config (retries = {"max_attempts" : 1000 , "mode" : "adaptive" }),
39
43
)
40
44
41
45
42
46
def test_s3_client_without_cloud_space_id (monkeypatch ):
43
- boto3 = mock .MagicMock ()
47
+ boto3_session = mock .MagicMock ()
48
+ boto3 = mock .MagicMock (Session = boto3_session )
44
49
monkeypatch .setattr (client , "boto3" , boto3 )
45
50
46
51
botocore = mock .MagicMock ()
@@ -59,13 +64,14 @@ def test_s3_client_without_cloud_space_id(monkeypatch):
59
64
assert s3 .client
60
65
assert s3 .client
61
66
62
- boto3 .client .assert_called_once ()
67
+ boto3_session () .client .assert_called_once ()
63
68
64
69
65
70
@pytest .mark .skipif (sys .platform == "win32" , reason = "not supported on windows" )
66
71
@pytest .mark .parametrize ("use_shared_credentials" , [False , True , None ])
67
72
def test_s3_client_with_cloud_space_id (use_shared_credentials , monkeypatch ):
68
- boto3 = mock .MagicMock ()
73
+ boto3_session = mock .MagicMock ()
74
+ boto3 = mock .MagicMock (Session = boto3_session )
69
75
monkeypatch .setattr (client , "boto3" , boto3 )
70
76
71
77
botocore = mock .MagicMock ()
@@ -85,14 +91,14 @@ def test_s3_client_with_cloud_space_id(use_shared_credentials, monkeypatch):
85
91
s3 = client .S3Client (1 )
86
92
assert s3 .client
87
93
assert s3 .client
88
- boto3 .client .assert_called_once ()
94
+ boto3_session () .client .assert_called_once ()
89
95
sleep (1 - (time () - s3 ._last_time ))
90
96
assert s3 .client
91
97
assert s3 .client
92
- assert len (boto3 .client ._mock_mock_calls ) == 6
98
+ assert len (boto3_session () .client ._mock_mock_calls ) == 6
93
99
sleep (1 - (time () - s3 ._last_time ))
94
100
assert s3 .client
95
101
assert s3 .client
96
- assert len (boto3 .client ._mock_mock_calls ) == 9
102
+ assert len (boto3_session () .client ._mock_mock_calls ) == 9
97
103
98
104
assert instance_metadata_provider ._mock_call_count == 0 if use_shared_credentials else 3
0 commit comments