Made S3 client injectable to ease mocking for testing

This commit is contained in:
Pablo Martin 2022-12-30 15:47:13 +01:00
parent f1ed3832e5
commit f684b2a043

View file

@ -62,17 +62,21 @@ class LolaConfig:
DEFAULT_KUBERNETES_IMAGE if kubernetes_image is None else kubernetes_image
)
def fetch_slack_webhooks(self) -> None:
def fetch_slack_webhooks(self, s3_client=None) -> None:
"""
Read the slack webhooks file from S3 and store the webhooks in memory.
:param s3_client: a client to fetch files from S3.
:return: None
"""
if s3_client is None:
s3_client = boto3.client("s3")
self.SLACK_WEBHOOKS = json.loads(
boto3.client("s3")
.get_object(Bucket=self.S3_BUCKET_NAME, Key=self.SLACK_WEBHOOKS_FILE)[
"Body"
]
s3_client.get_object(
Bucket=self.S3_BUCKET_NAME, Key=self.SLACK_WEBHOOKS_FILE
)["Body"]
.read()
.decode("utf-8")
)