-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from Aiven-Open/joelynch/expose-config
Expose config models
- Loading branch information
Showing
12 changed files
with
122 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from rohmu.factory import Config, get_class_for_transfer, get_transfer | ||
from rohmu.factory import Config, get_class_for_transfer, get_transfer, get_transfer_from_model | ||
from rohmu.object_storage.config import S3ObjectStorageConfig | ||
from rohmu.object_storage.s3 import S3Transfer | ||
from typing import cast | ||
from unittest.mock import ANY, MagicMock, Mock, patch | ||
|
||
import pytest | ||
|
@@ -42,18 +41,17 @@ def test_get_transfer_s3( | |
config: Config, | ||
) -> None: | ||
expected_config_arg = dict(config) | ||
expected_config_arg.pop("storage_type") | ||
expected_config_arg.pop("notifier") | ||
expected_botocore_config = {"proxies": {"https": "socks5://bob:[email protected]:16666"}} | ||
mock_config_model.return_value = S3ObjectStorageConfig(**expected_config_arg, notifier=None) | ||
mock_config_model.return_value = S3ObjectStorageConfig(**expected_config_arg) | ||
|
||
transfer_object = get_transfer(config) | ||
|
||
mock_config_model.assert_called_once_with(**expected_config_arg, notifier=mock_notifier()) | ||
mock_from_model.assert_called_once_with(mock_config_model()) | ||
mock_config_model.assert_called_once_with(**expected_config_arg) | ||
mock_from_model.assert_called_once_with(mock_config_model(), mock_notifier.return_value) | ||
mock_notifier.assert_called_once_with(url=config["notifier"]["url"]) | ||
assert isinstance(transfer_object, S3Transfer) | ||
# cast was the easiest way to convince mypy | ||
assert cast(S3Transfer, transfer_object).bucket_name == "dummy-bucket" | ||
assert transfer_object.bucket_name == "dummy-bucket" | ||
mock_botocore_config.assert_called_once_with(**expected_botocore_config) | ||
mock_s3_client.assert_called_once_with( | ||
session=ANY, | ||
|
@@ -70,3 +68,29 @@ def test_get_transfer_s3( | |
@patch.dict(sys.modules, {"swiftclient": MagicMock(), "azure.common": MagicMock()}) | ||
def test_config_model_defined(storage_type: str) -> None: | ||
assert get_class_for_transfer({"storage_type": storage_type}).config_model | ||
|
||
|
||
@patch("rohmu.object_storage.s3.create_s3_client") | ||
def test_get_transfer_from_model( | ||
create_s3_client: Mock, | ||
) -> None: | ||
config = S3ObjectStorageConfig( | ||
region="dummy-region", | ||
bucket_name="dummy-bucket", | ||
proxy_info={ | ||
"host": "proxy.test", | ||
"port": "16666", | ||
"type": "socks5", | ||
"user": "bob", | ||
"pass": "secret", | ||
}, | ||
) | ||
get_transfer_from_model(config) | ||
create_s3_client.assert_called_once_with( | ||
session=ANY, | ||
config=ANY, | ||
aws_access_key_id=None, | ||
aws_secret_access_key=None, | ||
aws_session_token=None, | ||
region_name="dummy-region", | ||
) |