How to use test_nested_stack method in localstack

Best Python code snippet using localstack_python

test_cfn_resources.py

Source:test_cfn_resources.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: UTF-8 -*-3# authors:4# Tony Vattathil <tonynv@amazon.com>, <avattathil@gmail.com>5# Santiago Cardenas <sancard@amazon.com>, <santiago[dot]cardenas[at]outlook[dot]com>6# Shivansh Singh <sshvans@amazon.com>,7# Jay McConnell <jmmccon@amazon.com>,8# Andrew Glenn <andglenn@amazon.com>9from __future__ import print_function10import unittest11import mock12from taskcat.client_factory import ClientFactory13from taskcat.cfn_resources import CfnResourceTools14from taskcat.exceptions import TaskCatException15def client_factory_instance():16 with mock.patch.object(ClientFactory, '__init__', return_value=None):17 aws_clients = ClientFactory(None)18 aws_clients._credential_sets = {'default': [None, None, None, None]}19 return aws_clients20def cfn_resource_tools_instance():21 return CfnResourceTools(client_factory_instance())22def mock_get_resources_helper(self, stackname, region, l_resources, include_stacks):23 l_resources.append("test_resource")24def mock_get_resources(self, stackname, region, include_stacks=False):25 return []26def mock_boto_get(service, region):27 return MockCfn()28class MockCfn(object):29 def __init__(self):30 pass31 def describe_stack_resources(self, StackName):32 outp = {"StackResources": []}33 if StackName == "test_stack":34 outp["StackResources"].append({35 "ResourceType": "test_type",36 "PhysicalResourceId": "test_pid",37 "LogicalResourceId": "test_lid"38 })39 elif StackName == "test_nested_stack":40 outp["StackResources"].append({41 "ResourceType": "AWS::CloudFormation::Stack",42 "PhysicalResourceId": "test_stack",43 "LogicalResourceId": "test_stack"44 })45 elif StackName == "test_raise":46 raise ValueError47 elif StackName == "test_raise_tcat":48 raise TaskCatException49 return outp50class TestCfnResourceTools(unittest.TestCase):51 def test___init__(self):52 client_factory = client_factory_instance()53 msg = "should store client factory in self._boto_client"54 cfn_resource = CfnResourceTools(client_factory)55 self.assertEqual(client_factory, cfn_resource._boto_client, msg)56 def test_get_resources(self):57 cfn_resource_tools = cfn_resource_tools_instance()58 msg = "should return a list of resources"59 with mock.patch("taskcat.cfn_resources.CfnResourceTools.get_resources_helper", mock_get_resources_helper):60 resources = cfn_resource_tools.get_resources("test_stack", "us-east-1")61 self.assertEqual(["test_resource"], resources, msg)62 def test_get_resources_helper(self):63 cfn_resource_tools = cfn_resource_tools_instance()64 cfn_resource_tools._boto_client.get = mock_boto_get65 msg = "should return expected list of resources"66 actual = []67 cfn_resource_tools.get_resources_helper("test_stack", "us-east-1", actual, False)68 self.assertEqual([{'resourceType': 'test_type', 'physicalId': 'test_pid', 'logicalId': 'test_lid'}], actual, msg)69 msg = "should return expected list of resources"70 actual = []71 cfn_resource_tools.get_resources_helper("test_nested_stack", "us-east-1", actual, True)72 expected = [73 {'logicalId': 'test_stack', 'physicalId': 'test_stack', 'resourceType': 'AWS::CloudFormation::Stack'},74 {'logicalId': 'test_lid', 'physicalId': 'test_pid', 'resourceType': 'test_type'}75 ]76 self.assertEqual(expected, actual, msg)77 msg = "should raise Taskcat error with specific message"78 actual = []79 with self.assertRaises(TaskCatException) as e:80 cfn_resource_tools.get_resources_helper("test_raise", "us-east-1", actual, False)81 self.assertEqual("Unable to get resources for stack test_raise", str(e.exception), msg)82 def test_get_all_resources(self):83 cfn_resource_tools = cfn_resource_tools_instance()84 msg = "should return a list of resources"85 with mock.patch("taskcat.cfn_resources.CfnResourceTools.get_resources", mock_get_resources):86 resources = cfn_resource_tools.get_all_resources(["test_stack"], "us-east-1")...

Full Screen

Full Screen

test_nested_stack.py

Source:test_nested_stack.py Github

copy

Full Screen

...61 params = parser.Parameters(stack_name, tmpl, {})62 stack = parser.Stack(ctx, stack_name, tmpl, params)63 stack.store()64 return stack65 def test_nested_stack(self):66 urlfetch.get('https://localhost/the.template').AndReturn(67 self.nested_template)68 self.m.ReplayAll()69 stack = self.create_stack(self.test_template)70 resource = stack['the_nested']71 self.assertTrue(resource.FnGetRefId().startswith(72 'arn:openstack:heat::aaaa:stacks/test_stack.the_nested/'))73 self.assertEqual(nested_stack.NestedStack.UPDATE_REPLACE,74 resource.handle_update({}))75 self.assertEqual('bar', resource.FnGetAtt('Outputs.Foo'))76 self.assertRaises(77 exception.InvalidTemplateAttribute, resource.FnGetAtt, 'Foo')78 resource.delete()79 self.assertTrue(resource.FnGetRefId().startswith(...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful