forked from apache/iceberg-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fsspec_profile.py
More file actions
106 lines (88 loc) · 3.78 KB
/
test_fsspec_profile.py
File metadata and controls
106 lines (88 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
import uuid
from unittest import mock
from pyiceberg.io.fsspec import FsspecFileIO
from pyiceberg.typedef import Properties
from tests.conftest import UNIFIED_AWS_SESSION_PROPERTIES
def test_fsspec_s3_session_properties_with_profile() -> None:
session_properties: Properties = {
"s3.profile-name": "test-profile",
"s3.endpoint": "http://localhost:9000",
**UNIFIED_AWS_SESSION_PROPERTIES,
}
with mock.patch("s3fs.S3FileSystem") as mock_s3fs:
s3_fileio = FsspecFileIO(properties=session_properties)
filename = str(uuid.uuid4())
s3_fileio.new_input(location=f"s3://warehouse/{filename}")
mock_s3fs.assert_called_with(
anon=False,
client_kwargs={
"endpoint_url": "http://localhost:9000",
"aws_access_key_id": "client.access-key-id",
"aws_secret_access_key": "client.secret-access-key",
"region_name": "client.region",
"aws_session_token": "client.session-token",
},
config_kwargs={},
profile="test-profile",
)
def test_fsspec_s3_session_properties_with_client_profile() -> None:
session_properties: Properties = {
"client.profile-name": "test-profile",
"s3.endpoint": "http://localhost:9000",
**UNIFIED_AWS_SESSION_PROPERTIES,
}
with mock.patch("s3fs.S3FileSystem") as mock_s3fs:
s3_fileio = FsspecFileIO(properties=session_properties)
filename = str(uuid.uuid4())
s3_fileio.new_input(location=f"s3://warehouse/{filename}")
mock_s3fs.assert_called_with(
anon=False,
client_kwargs={
"endpoint_url": "http://localhost:9000",
"aws_access_key_id": "client.access-key-id",
"aws_secret_access_key": "client.secret-access-key",
"region_name": "client.region",
"aws_session_token": "client.session-token",
},
config_kwargs={},
profile="test-profile",
)
def test_fsspec_s3_session_properties_with_s3_and_client_profile() -> None:
session_properties: Properties = {
"s3.profile-name": "s3-profile",
"client.profile-name": "client-profile",
"s3.endpoint": "http://localhost:9000",
**UNIFIED_AWS_SESSION_PROPERTIES,
}
with mock.patch("s3fs.S3FileSystem") as mock_s3fs:
s3_fileio = FsspecFileIO(properties=session_properties)
filename = str(uuid.uuid4())
s3_fileio.new_input(location=f"s3://warehouse/{filename}")
mock_s3fs.assert_called_with(
anon=False,
client_kwargs={
"endpoint_url": "http://localhost:9000",
"aws_access_key_id": "client.access-key-id",
"aws_secret_access_key": "client.secret-access-key",
"region_name": "client.region",
"aws_session_token": "client.session-token",
},
config_kwargs={},
profile="s3-profile",
)