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_init(self):
test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
c = Config.create(
project_config_path=test_proj / ".taskcat.yml", project_root=test_proj
)
templates = c.get_templates(project_root=test_proj)
template = templates["taskcat-json"]
self.assertEqual(1, len(template.children))
self.assertEqual(4, len(template.descendents))
def test_lint(self, m_boto):
cwd = os.getcwd()
base_path = "/tmp/lint_test/"
mkdir(base_path)
try:
for test_case in test_cases:
config_path = Path(build_test_case(base_path, test_case)).resolve()
project_root = config_path.parent.parent
config = Config.create(
project_config_path=config_path, project_root=project_root
)
templates = config.get_templates(project_root=project_root)
lint = Lint(config=config, templates=templates)
self.assertEqual(
test_case["expected_lints"], flatten_rule(lint.lints[0])
)
finally:
shutil.rmtree(base_path)
os.chdir(cwd)
pass
def create_ephemeral_template_object(self, template_type="generic"):
test_proj = (
Path(__file__).parent / f"./data/update_ami/{template_type}"
).resolve()
c = Config.create(
project_config_path=test_proj / ".taskcat.yml", project_root=test_proj
)
templates = c.get_templates(project_root=test_proj)
return templates
def test_passed(self, m_boto):
cwd = os.getcwd()
try:
config_path = Path(
build_test_case("/tmp/lint_test_output/", test_cases[0])
).resolve()
project_root = config_path.parent.parent
config = Config.create(
project_config_path=config_path, project_root=project_root
)
templates = config.get_templates(project_root)
lint = Lint(config=config, templates=templates)
self.assertEqual(lint.passed, True)
lint_key = list(lint.lints[0])[0]
result_key = list(lint.lints[0][lint_key]["results"])[0]
test = lint.lints[0][lint_key]["results"][result_key]
rule = mock.Mock(return_val="[E0001] some error")
rule.rule.id = "E0001"
rule.linenumber = 123
rule.rule.shortdesc = "short error"
rule.message = "some error"
test.append(rule)
lint.strict = True
def test_config(self):
base_path = "./" if os.getcwd().endswith("/tests") else "./tests/"
base_path = Path(base_path + "data/config_inheritance").resolve()
config = Config.create(
args={"project": {"build_submodules": False}},
global_config_path=base_path / ".taskcat_global.yml",
project_config_path=base_path / "./.taskcat.yml",
overrides_path=base_path / "./.taskcat_overrides.yml",
env_vars={"TASKCAT_PROJECT_PACKAGE_LAMBDA": "False"},
)
expected = {
"general": {
"parameters": {
"GlobalVar": "set_in_global",
"OverridenVar": "set_in_global",
},
"s3_bucket": "set-in-global",
},
"project": {
def test_standalone_template(self):
base_path = "./" if os.getcwd().endswith("/tests") else "./tests/"
base_path = Path(base_path + "data/legacy_test/templates/").resolve()
Config.create(template_file=base_path / "test.template.yaml")
def client_factory_instance():
with mock.patch.object(Boto3Cache, "__init__", return_value=None):
aws_clients = Boto3Cache(None)
aws_clients._credential_sets = {"default": [None, None, None, None]}
aws_clients.logger = logger
return aws_clients
def test_session_invalid_profile(self, mock_cache_lookup, mock_cache_set):
mock_cache_lookup.side_effect = ProfileNotFound(profile="non-existent-profile")
cache = Boto3Cache()
with self.assertRaises(ProfileNotFound):
cache.session(profile="non-existent-profile")
self.assertEqual(mock_cache_lookup.called, False)
cache._get_region = mock.Mock(return_value="us-east-1")
with self.assertRaises(ProfileNotFound):
cache.session(profile="non-existent-profile")
self.assertEqual(mock_cache_lookup.called, True)
def client_factory_instance():
with mock.patch.object(Boto3Cache, "__init__", return_value=None):
aws_clients = Boto3Cache(None)
aws_clients._credential_sets = {"default": [None, None, None, None]}
aws_clients.logger = logger
return aws_clients