Skip to content

Commit

Permalink
Merge pull request #147 from Aiven-Open/joelynch/notifier-fix
Browse files Browse the repository at this point in the history
factory: allow no notifier config in get_transfer

#147
  • Loading branch information
kmichel-aiven authored Oct 11, 2023
2 parents 013b2bb + 75cac10 commit b99f193
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions rohmu/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class ProxyInfo(RohmuModel):
user: Optional[str]
password: Optional[str] = pydantic.Field(None, alias="pass")

class Config(RohmuModel.Config):
# Allow ProxyInfo(**proxy_info.dict()) to work with the alias
allow_population_by_field_name = True


class StorageModel(pydantic.BaseModel):
storage_type: StorageDriver
Expand Down
6 changes: 4 additions & 2 deletions rohmu/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def get_transfer_model(storage_config: Config) -> StorageModel:

def get_transfer(storage_config: Config) -> BaseTransfer[Any]:
storage_config = storage_config.copy()
noitifier_config = storage_config.pop("notifier")
notifier = get_notifier(noitifier_config)
noitifier_config = storage_config.pop("notifier", None)
notifier = None
if noitifier_config is not None:
notifier = get_notifier(noitifier_config)
model = get_transfer_model(storage_config)
return get_transfer_from_model(model, notifier)

Expand Down
26 changes: 26 additions & 0 deletions test/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,29 @@ def test_get_transfer_from_model(
aws_session_token=None,
region_name="dummy-region",
)


@patch("rohmu.object_storage.s3.create_s3_client")
def test_get_transfer_serialized_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(config.dict())
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",
)

0 comments on commit b99f193

Please sign in to comment.