Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_available_azs_with_excludes(self):
class_kwargs = {**self.class_kwargs, "az_excludes": {"use1-az6", "use1-az5"}}
pg = ParamGen(**class_kwargs)
pg._boto_client = MockClient
returned_azs = pg.get_available_azs(4)
returned_az_list = returned_azs.split(",")
test_criteria = [
# tuple (first_param, second_param, test_description)
(len(returned_az_list), 4, "Verifying we return 4 AZs"),
(len(set(returned_az_list)), 4, "Verifying we return 4 *unique* AZs"),
(
("us-east-1a" not in returned_az_list),
True,
"Verifying us-east-1a is not returned.",
),
(
("us-east-1b" not in returned_az_list),
True,
"Verifying us-east-1b is not returned.",
def test_genaz_raises_taskcat_exception(self):
pg = ParamGen(**self.class_kwargs)
pg._boto_client = MockSingleAZClient
with self.assertRaises(TaskCatException):
pg.get_available_azs(2)
"LocalOverrideTest": "override",
"PasswordA": "$[taskcat_genpass_8A]",
"PasswordAConfirm": "$[taskcat_getval_PasswordA]",
"PasswordB": "$[taskcat_genpass_32S]",
"RandomNumber": "$[taskcat_random-numbers]",
"RandomString": "$[taskcat_random-string]",
"SingleAZ": "$[taskcat_getsingleaz_2]",
"StackName": "TestStack",
"UUID": "$[taskcat_genuuid]",
}
bclient = MockClient
bclient.logger = logger
class_kwargs = self.class_kwargs
class_kwargs["param_dict"] = input_params
class_kwargs["boto_client"] = bclient
pg = ParamGen(**class_kwargs)
pg.transform_parameter()
ignore_patterns = ["RE_COUNT"]
missed_regex_patterns = []
regex_pattern_text = set()
_found = False
for rp in self.regex_patterns:
regex_pattern_text.add(rp.test_pattern_attribute)
for _param_key, param_value in pg.results.items():
if rp.test_pattern_attribute in ignore_patterns:
continue
with self.subTest(
"Transformed Value: {} must not match Regex: {}".format(
param_value, rp.test_pattern_attribute
)
):
self.assertNotRegex(
def test_all_regexes_tested(self):
regex_type = type(re.compile(""))
tested_expressions = {x.test_pattern_attribute for x in self.regex_patterns}
all_expressions = {
x for x in dir(ParamGen) if type(getattr(ParamGen, x)) == regex_type
}
self.assertEqual(all_expressions, tested_expressions)
def test_convert_to_str(self):
pg = ParamGen(**self.class_kwargs)
pg.param_name = "test_param"
pg.param_value = 1234
pg.convert_to_str()
self.assertEqual(pg.param_value, "1234")
def test_regex_replace_param_value(self):
pg = ParamGen(**self.class_kwargs)
pg.param_name = "test_param"
pg.param_value = "example-foo-value"
re_pattern = re.compile("foo")
pg._regex_replace_param_value(re_pattern, "bar")
self.assertEqual(pg.param_value, "example-bar-value")
def test_regxfind(self):
pg = ParamGen(**self.class_kwargs)
re_object = re.compile("foo")
self.assertEqual(pg.regxfind(re_object, "aslkjfafoo"), "foo")
def test_special_regular_expression(self):
pg = ParamGen(**self.class_kwargs)
self.assertEqual(pg.regxfind(ParamGen.RE_COUNT, "$[taskcat_getaz_2]"), "2")
self.assertEqual(pg.regxfind(ParamGen.RE_COUNT, "$[taskcat_genpass_8]"), "8")
def test_get_content(self):
pg = ParamGen(**self.class_kwargs)
pg._boto_client = MockClient
self.assertEqual(
pg.get_content(bucket="unit-test-bucket", object_key="unit-test-key"),
"unicorns",
)
def test_genpassword_type(self):
pg = ParamGen(**self.class_kwargs)
genpassword_criteria = [
# A tuple of (func_call, length, flags, re.Pattern, description)
(
pg.genpassword,
15,
None,
re.compile("[0-9A-Za-z]"),
"Testing a 15 character password. Default PW type",
),
(
pg.genpassword,
15,
"S",
re.compile(r"[!#\$&{\*:\[=,\]-_%@\+a-zA-Z0-9]+"),
"Testing a 15 character password, Special Characters Type",
),