|
| 1 | + |
| 2 | +from unittest import mock |
| 3 | +import pytest |
| 4 | +from pyiceberg.io.fsspec import FsspecFileIO |
| 5 | +from pyiceberg.typedef import Properties |
| 6 | + |
| 7 | +UNIFIED_AWS_SESSION_PROPERTIES = { |
| 8 | + "client.access-key-id": "client.access-key-id", |
| 9 | + "client.secret-access-key": "client.secret-access-key", |
| 10 | + "client.region": "client.region", |
| 11 | + "client.session-token": "client.session-token", |
| 12 | +} |
| 13 | +import uuid |
| 14 | + |
| 15 | +def test_fsspec_s3_session_properties_with_profile() -> None: |
| 16 | + session_properties: Properties = { |
| 17 | + "s3.profile-name": "test-profile", |
| 18 | + "s3.endpoint": "http://localhost:9000", |
| 19 | + **UNIFIED_AWS_SESSION_PROPERTIES, |
| 20 | + } |
| 21 | + |
| 22 | + with mock.patch("s3fs.S3FileSystem") as mock_s3fs, mock.patch("aiobotocore.session.AioSession") as mock_aio_session: |
| 23 | + s3_fileio = FsspecFileIO(properties=session_properties) |
| 24 | + filename = str(uuid.uuid4()) |
| 25 | + |
| 26 | + s3_fileio.new_input(location=f"s3://warehouse/{filename}") |
| 27 | + |
| 28 | + mock_aio_session.assert_called_with(profile="test-profile") |
| 29 | + mock_s3fs.assert_called_with( |
| 30 | + anon=False, |
| 31 | + client_kwargs={ |
| 32 | + "endpoint_url": "http://localhost:9000", |
| 33 | + "aws_access_key_id": "client.access-key-id", |
| 34 | + "aws_secret_access_key": "client.secret-access-key", |
| 35 | + "region_name": "client.region", |
| 36 | + "aws_session_token": "client.session-token", |
| 37 | + }, |
| 38 | + config_kwargs={}, |
| 39 | + session=mock_aio_session(), |
| 40 | + ) |
| 41 | + |
| 42 | +def test_fsspec_s3_session_properties_with_client_profile() -> None: |
| 43 | + session_properties: Properties = { |
| 44 | + "client.profile-name": "test-profile", |
| 45 | + "s3.endpoint": "http://localhost:9000", |
| 46 | + **UNIFIED_AWS_SESSION_PROPERTIES, |
| 47 | + } |
| 48 | + |
| 49 | + with mock.patch("s3fs.S3FileSystem") as mock_s3fs, mock.patch("aiobotocore.session.AioSession") as mock_aio_session: |
| 50 | + s3_fileio = FsspecFileIO(properties=session_properties) |
| 51 | + filename = str(uuid.uuid4()) |
| 52 | + |
| 53 | + s3_fileio.new_input(location=f"s3://warehouse/{filename}") |
| 54 | + |
| 55 | + mock_aio_session.assert_called_with(profile="test-profile") |
| 56 | + mock_s3fs.assert_called_with( |
| 57 | + anon=False, |
| 58 | + client_kwargs={ |
| 59 | + "endpoint_url": "http://localhost:9000", |
| 60 | + "aws_access_key_id": "client.access-key-id", |
| 61 | + "aws_secret_access_key": "client.secret-access-key", |
| 62 | + "region_name": "client.region", |
| 63 | + "aws_session_token": "client.session-token", |
| 64 | + }, |
| 65 | + config_kwargs={}, |
| 66 | + session=mock_aio_session(), |
| 67 | + ) |
0 commit comments