Skip to content

Commit

Permalink
fixup! feat(lint): support ruff C4 check
Browse files Browse the repository at this point in the history
  • Loading branch information
haidarCheaito committed Jan 2, 2024
1 parent c75f087 commit 90c5b85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
30 changes: 16 additions & 14 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,18 @@ def create_zip() -> bytes:
archive.writestr(
"docker-compose.yml",
docker_compose_path.read_text().replace(
"${IMAGE_TAG}", version_label,
"${IMAGE_TAG}",
version_label,
),
)
if platform_hooks_path is not None:
for file in filter(
lambda path: path.is_file(), platform_hooks_path.glob("**/*"),
lambda path: path.is_file(),
platform_hooks_path.glob("**/*"),
):
archive.write(
file, arcname=file.relative_to(platform_hooks_path),
file,
arcname=file.relative_to(platform_hooks_path),
)

logging.info("Deployment archive created")
Expand All @@ -134,7 +137,9 @@ def create_zip() -> bytes:

def upload_zip(content: bytes) -> DeploymentArchive:
boto3.client("s3").put_object(
Bucket=bucket_name, Body=content, Key=bucket_key,
Bucket=bucket_name,
Body=content,
Key=bucket_key,
)
logging.info(
f"Deployment archive uploaded to s3://{bucket_name}/{bucket_key}",
Expand All @@ -156,7 +161,9 @@ class ApplicationVersion:

@classmethod
def get(
cls, application: BeanstalkApplication, version_label: str,
cls,
application: BeanstalkApplication,
version_label: str,
) -> Optional[Self]:
versions = boto3.client("elasticbeanstalk").describe_application_versions(
ApplicationName=application.name,
Expand Down Expand Up @@ -202,11 +209,7 @@ def wait_until_created():
step = 0
while step < polling_max_steps:
application_version = cls.get(application, version_label)
status = (
"UNAVAILABLE"
if application_version is None
else application_version.status
)
status = "UNAVAILABLE" if application_version is None else application_version.status

logging.info(
f"Step {step + 1} of {polling_max_steps}. Status is {status}",
Expand Down Expand Up @@ -319,9 +322,7 @@ def main():
description=os.environ["VERSION_DESCRIPTION"],
docker_compose_path=Path(os.environ["DOCKER_COMPOSE_PATH"]),
environment_name=os.environ["ENVIRONMENT_NAME"],
platform_hooks_path=Path(os.environ["PLATFORM_HOOKS_PATH"])
if os.environ["PLATFORM_HOOKS_PATH"]
else None,
platform_hooks_path=Path(os.environ["PLATFORM_HOOKS_PATH"]) if os.environ["PLATFORM_HOOKS_PATH"] else None,
region=get_region(),
version_label=os.environ["VERSION_LABEL"],
)
Expand All @@ -330,7 +331,8 @@ def main():
environment = BeanstalkEnvironment(application, config.environment_name)

application_version = get_or_create_beanstalk_application_version(
application, config,
application,
config,
)

application_version.deploy_to_environment(environment)
Expand Down
25 changes: 17 additions & 8 deletions test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
)
MOCK_APPLICATION = action.BeanstalkApplication(MOCK_CONFIG.application_name)
MOCK_ENVIRONMENT = action.BeanstalkEnvironment(
MOCK_APPLICATION, MOCK_CONFIG.environment_name,
MOCK_APPLICATION,
MOCK_CONFIG.environment_name,
)
MOCK_APPLICATION_VERSION = action.ApplicationVersion(
MOCK_APPLICATION, "version-0", "PROCESSED",
MOCK_APPLICATION,
"version-0",
"PROCESSED",
)
MOCK_TIME = datetime.now(tz=UTC)


class TestUtils(TestCase):
def test_check_aws_credentials(self):
with patch.dict(
os.environ, {"AWS_ACCESS_KEY_ID": "fake", "AWS_SECRET_ACCESS_KEY": "fake"},
os.environ,
{"AWS_ACCESS_KEY_ID": "fake", "AWS_SECRET_ACCESS_KEY": "fake"},
):
action.check_aws_credentials()

Expand All @@ -49,10 +53,12 @@ def test_get_region(self):

class TestApplicationVersion(TestCase):
def _get_or_create_application_version(
self, polling_results: Sequence[Optional[action.ApplicationVersion]],
self,
polling_results: Sequence[Optional[action.ApplicationVersion]],
):
with NamedTemporaryFile() as docker_compose_file, patch.object(
action, "boto3",
action,
"boto3",
), patch.object(
action.ApplicationVersion,
"get",
Expand All @@ -68,7 +74,8 @@ def _get_or_create_application_version(
polling_max_steps=len(polling_results) - 1,
)
self.assertEqual(
mock_get_application_version.call_count, len(polling_results),
mock_get_application_version.call_count,
len(polling_results),
)
return result

Expand Down Expand Up @@ -133,7 +140,8 @@ def _deploy(
self.assertEqual(mock_get_events.call_count, iterations)
mock_is_active_in_environment.assert_called_with(MOCK_ENVIRONMENT)
self.assertEqual(
mock_is_active_in_environment.call_count, len(is_active_in_environment),
mock_is_active_in_environment.call_count,
len(is_active_in_environment),
)

def test_successful_deployment(self):
Expand All @@ -148,7 +156,8 @@ def test_successful_deployment(self):
def test_environment_timeout_error(self, *_):
with self.assertRaises(TimeoutError):
self._deploy(
({"Status": "InProgress", "Color": "Grey"},) * 5, (False, True),
({"Status": "InProgress", "Color": "Grey"},) * 5,
(False, True),
)

def test_health_failed(self):
Expand Down

0 comments on commit 90c5b85

Please sign in to comment.