Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmcginty committed May 14, 2024
1 parent cbb320b commit 4fb4b6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/aibs_informatics_cdk_lib/constructs_/ssm/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def upload_asset(
if destination_key_prefix is None:
destination_key_prefix = S3KeyPrefix(self.CODE_ASSETS_PREFIX)

parameter_name = self.env_base.get_ssm_param_name(param_name)
if param_name:
parameter_name = self.env_base.get_ssm_param_name(param_name)
else:
parameter_name = self.env_base.get_ssm_param_name(*param_name_components)

filename = f"{asset_name}-asset.zip"

s3deployment.BucketDeployment(
Expand Down Expand Up @@ -85,9 +89,7 @@ def upload_file(
)

# Store the S3 URI location in an SSM parameter
s3_uri = S3URI.build(
destination_bucket.bucket_name, destination_key, full_validate=False
)
s3_uri = S3URI.build(destination_bucket.bucket_name, destination_key, full_validate=False)

parameter_name = self.env_base.get_ssm_param_name(*param_name_components)
cmd_wrapper_param = ssm.StringParameter(
Expand Down
22 changes: 11 additions & 11 deletions test/aibs_informatics_cdk_lib/project/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class EnvTests(BaseTest):
def test__parse_obj__parses_simple_dict(self):
def test__model_validate__parses_simple_dict(self):
env_dict = {
"env_type": "prod",
"label": "marmot",
Expand All @@ -29,10 +29,10 @@ def test__parse_obj__parses_simple_dict(self):
account="12345678910",
region="us-west-2",
)
parsed_env = Env.parse_obj(env_dict)
parsed_env = Env.model_validate(env_dict)
self.assertEqual(expected_env, parsed_env)

def test__parse_obj__parses_dict_with_env_fields(self):
def test__model_validate__parses_dict_with_env_fields(self):
self.set_env_vars(
*list(dict(CUSTOM_LABEL="marmot", CUSTOM_ACCOUNT_ID="123123123").items())
)
Expand All @@ -49,12 +49,12 @@ def test__parse_obj__parses_dict_with_env_fields(self):
account="123123123",
region="{CUSTOM_REGION}",
)
parsed_env = Env.parse_obj(env_dict)
parsed_env = Env.model_validate(env_dict)
self.assertEqual(expected_env, parsed_env)

def test__parse_obj__invalid_dict__FAILS(self):
def test__model_validate__invalid_dict__FAILS(self):
with self.assertRaises(Exception):
Env.parse_obj({"env_type": "not_valid"})
Env.model_validate({"env_type": "not_valid"})

def test__env_base__includes_label_when_present_and_not_otherwise(self):
env_with_label = Env(env_type=EnvType.PROD, label="marmot")
Expand Down Expand Up @@ -120,9 +120,9 @@ def test__get_stage_config__simple_override(self):
default_config_overrides=default_config_overrides,
)

expected_config = StageConfig.parse_obj(
expected_config = StageConfig.model_validate(
{
**default_config.copy().dict(exclude_unset=True),
**default_config.model_copy().model_dump(exclude_unset=True),
}
)
expected_config.env.env_type = EnvType.DEV
Expand All @@ -141,7 +141,7 @@ def test__parse_file__test_loads_json_and_yml(self):
default_config_overrides={},
)
proj_config_json_path = self.tmp_path() / "project.json"
proj_config_json_path.write_text(proj_config.json())
proj_config_json_path.write_text(proj_config.model_dump_json())
another_proj_config = ProjectConfig.load_config(proj_config_json_path)
self.assertEqual(proj_config, another_proj_config)

Expand All @@ -154,7 +154,7 @@ def test__get_stage_config__fails_with_invalid_env_type(self):
default_config_overrides={EnvType.DEV: {}, EnvType.TEST: {}},
)
proj_config_json_path = self.tmp_path() / "project.json"
proj_config_json_path.write_text(proj_config.json())
proj_config_json_path.write_text(proj_config.model_dump_json())

with self.assertRaises(ValueError):
ConfigProvider.get_stage_config("invalid", proj_config_json_path)
Expand All @@ -166,7 +166,7 @@ def test__get_config__simple_check(self):
default_config_overrides={EnvType.DEV: {}, EnvType.TEST: {}},
)
proj_config_json_path = self.tmp_path() / "project.json"
proj_config_json_path.write_text(proj_config.json())
proj_config_json_path.write_text(proj_config.model_dump_json())

# no overrides means they should be equal
self.assertEqual(
Expand Down

0 comments on commit 4fb4b6b

Please sign in to comment.