def test_stack_functions(self): project_settings = ProjectSettings(name="python_test", runtime="python") ws = LocalWorkspace(project_settings=project_settings) stack_1_name = f"python_int_test_first_{get_test_suffix()}" stack_2_name = f"python_int_test_second_{get_test_suffix()}" # Create a stack ws.create_stack(stack_1_name) stacks = ws.list_stacks() stack_1 = get_stack(stacks, stack_1_name) # Check the stack exists self.assertIsNotNone(stack_1) # Check that it's current self.assertTrue(stack_1.current) # Create another stack ws.create_stack(stack_2_name) stacks = ws.list_stacks() stack_1 = get_stack(stacks, stack_1_name) stack_2 = get_stack(stacks, stack_2_name) # Check the second stack exists self.assertIsNotNone(stack_2) # Check that second stack is current but the first is not self.assertFalse(stack_1.current) self.assertTrue(stack_2.current) # Select the first stack again ws.select_stack(stack_1_name) stacks = ws.list_stacks() stack_1 = get_stack(stacks, stack_1_name) # Check the first stack is now current self.assertTrue(stack_1.current) # Get the current stack info current_stack = ws.stack() # Check that the name matches stack 1 self.assertEqual(current_stack.name, stack_1_name) # Remove both stacks ws.remove_stack(stack_1_name) ws.remove_stack(stack_2_name) stacks = ws.list_stacks() stack_1 = get_stack(stacks, stack_1_name) stack_2 = get_stack(stacks, stack_2_name) # Check that they were both removed self.assertIsNone(stack_1) self.assertIsNone(stack_2)
def test_stack_status_methods(self): project_name = "python_test" project_settings = ProjectSettings(name=project_name, runtime="python") ws = LocalWorkspace(project_settings=project_settings) stack_name = stack_namer(project_name) stack = Stack.create(stack_name, ws) history = stack.history() self.assertEqual(len(history), 0) info = stack.info() self.assertIsNone(info) ws.remove_stack(stack_name)
def test_stack_init(self): project_name = "python_test" project_settings = ProjectSettings(name=project_name, runtime="python") ws = LocalWorkspace(project_settings=project_settings) stack_name = stack_namer(project_name) Stack.create(stack_name, ws) # Trying to create the stack again throws an error self.assertRaises(StackAlreadyExistsError, Stack.create, stack_name, ws) # Stack.select succeeds self.assertEqual(Stack.select(stack_name, ws).name, stack_name) # Stack.create_or_select succeeds self.assertEqual(Stack.create_or_select(stack_name, ws).name, stack_name) ws.remove_stack(stack_name)
def test_config_flag_like(self): project_name = "python_test" project_settings = ProjectSettings(project_name, runtime="python") ws = LocalWorkspace(project_settings=project_settings) stack_name = stack_namer(project_name) stack = Stack.create(stack_name, ws) stack.set_config("key", ConfigValue(value="-value")) stack.set_config("secret-key", ConfigValue(value="-value", secret=True)) all_config = stack.get_all_config() self.assertFalse(all_config["python_test:key"].secret) self.assertEqual(all_config["python_test:key"].value, "-value") self.assertTrue(all_config["python_test:secret-key"].secret) self.assertEqual(all_config["python_test:secret-key"].value, "-value") ws.remove_stack(stack_name)
def test_bulk_config_ops(self): project_name = "python_test" project_settings = ProjectSettings(project_name, runtime="python") ws = LocalWorkspace(project_settings=project_settings) stack_name = stack_namer(project_name) stack = Stack.create(stack_name, ws) config: ConfigMap = { "one": ConfigValue(value="one"), "two": ConfigValue(value="two"), "three": ConfigValue(value="three", secret=True), "four": ConfigValue(value="four", secret=True), "five": ConfigValue(value="five"), "six": ConfigValue(value="six"), "seven": ConfigValue(value="seven", secret=True), "eight": ConfigValue(value="eight", secret=True), "nine": ConfigValue(value="nine"), "ten": ConfigValue(value="ten"), } stack.set_all_config(config) stack.remove_all_config([key for key in config]) ws.remove_stack(stack_name)
def test_config_functions(self): project_name = "python_test" project_settings = ProjectSettings(project_name, runtime="python") ws = LocalWorkspace(project_settings=project_settings) stack_name = stack_namer(project_name) stack = Stack.create(stack_name, ws) config: ConfigMap = { "plain": ConfigValue(value="abc"), "secret": ConfigValue(value="def", secret=True) } plain_key = normalize_config_key("plain", project_name) secret_key = normalize_config_key("secret", project_name) self.assertRaises(CommandError, stack.get_config, plain_key) values = stack.get_all_config() self.assertEqual(len(values), 0) stack.set_all_config(config) values = stack.get_all_config() self.assertEqual(values[plain_key].value, "abc") self.assertFalse(values[plain_key].secret) self.assertEqual(values[secret_key].value, "def") self.assertTrue(values[secret_key].secret) stack.remove_config("plain") values = stack.get_all_config() self.assertEqual(len(values), 1) stack.set_config("foo", ConfigValue(value="bar")) values = stack.get_all_config() self.assertEqual(len(values), 2) ws.remove_stack(stack_name)