Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"global": {
"AMIs": {
"AMZNLINUXHVM": {
"name": "amzn-ami-hvm-????.??.?.*-x86_64-gp2",
"owner-alias": "amazon",
}
}
}
}
expected = [
RegionalCodename(
region="us-east-1",
cn="AMZNLINUXHVM",
filters=[
EC2FilterValue("name", ["amzn-ami-hvm-????.??.?.*-x86_64-gp2"]),
EC2FilterValue("owner-alias", ["amazon"]),
EC2FilterValue("state", ["available"]),
],
)
]
actual = build_codenames(au_template, example_config_obj)
_mocked_dt = datetime.now()
for r1 in expected:
r1._creation_dt = _mocked_dt
for r2 in actual:
r2._creation_dt = _mocked_dt
self.assertEqual(expected, actual)
def test_regional_codename__hash__(self):
rc = RegionalCodename(
region="us-east-1",
cn="AMZNLINUXHVM",
filters=[
EC2FilterValue("name", ["amzn-ami-hvm-????.??.?.*-x86_64-gp2"]),
EC2FilterValue("owner-alias", ["amazon"]),
EC2FilterValue("state", ["available"]),
],
)
self.assertTrue(isinstance(rc.__hash__(), int))
def test_regional_codename__hash__(self):
rc = RegionalCodename(
region="us-east-1",
cn="AMZNLINUXHVM",
filters=[
EC2FilterValue("name", ["amzn-ami-hvm-????.??.?.*-x86_64-gp2"]),
EC2FilterValue("owner-alias", ["amazon"]),
EC2FilterValue("state", ["available"]),
],
)
self.assertTrue(isinstance(rc.__hash__(), int))
def test_construct_filters(self):
example_config_obj = AUConfig
example_config_obj.raw_dict = {
"global": {
"AMIs": {
"FOOBAR": {
"name": "amzn-ami-hvm-????.??.?.*-x86_64-gp2",
"owner-alias": "amazon",
}
}
}
}
expected = [
EC2FilterValue("name", ["amzn-ami-hvm-????.??.?.*-x86_64-gp2"]),
EC2FilterValue("owner-alias", ["amazon"]),
EC2FilterValue("state", ["available"]),
]
actual = _construct_filters("FOOBAR", example_config_obj)
self.assertEqual(expected, actual)
"AMIs": {
"AMZNLINUXHVM": {
"name": "amzn-ami-hvm-????.??.?.*-x86_64-gp2",
"owner-alias": "amazon",
}
}
}
}
expected = [
RegionalCodename(
region="us-east-1",
cn="AMZNLINUXHVM",
filters=[
EC2FilterValue("name", ["amzn-ami-hvm-????.??.?.*-x86_64-gp2"]),
EC2FilterValue("owner-alias", ["amazon"]),
EC2FilterValue("state", ["available"]),
],
)
]
actual = build_codenames(au_template, example_config_obj)
_mocked_dt = datetime.now()
for r1 in expected:
r1._creation_dt = _mocked_dt
for r2 in actual:
r2._creation_dt = _mocked_dt
self.assertEqual(expected, actual)
def _construct_filters(cname: str, config: Config) -> List[EC2FilterValue]:
formatted_filters: List[EC2FilterValue] = []
fetched_filters = config.get_filter(cname)
formatted_filters = [EC2FilterValue(k, [v]) for k, v in fetched_filters.items()]
if formatted_filters:
formatted_filters.append(EC2FilterValue("state", ["available"]))
return formatted_filters
def _construct_filters(cname: str, config: Config) -> List[EC2FilterValue]:
formatted_filters: List[EC2FilterValue] = []
fetched_filters = config.get_filter(cname)
formatted_filters = [EC2FilterValue(k, [v]) for k, v in fetched_filters.items()]
if formatted_filters:
formatted_filters.append(EC2FilterValue("state", ["available"]))
return formatted_filters