How to use detach_vpn_gateway method in localstack

Best Python code snippet using localstack_python

test_vpn_gateway.py

Source:test_vpn_gateway.py Github

copy

Full Screen

1# Copyright (c) 2017 GigaSpaces Technologies Ltd. All rights reserved2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# * See the License for the specific language governing permissions and13# * limitations under the License.14import unittest15from cloudify_awssdk.common.tests.test_base import TestBase, mock_decorator16from cloudify_awssdk.ec2.resources.vpn_gateway import EC2VPNGateway, \17 VPNGATEWAYS, VPNGATEWAY_ID, \18 VPC_ID, VPC_TYPE19from mock import patch, MagicMock20from cloudify_awssdk.ec2.resources import vpn_gateway21class TestEC2VPNGateway(TestBase):22 def setUp(self):23 self.vpn_gateway = EC2VPNGateway("ctx_node", resource_id=True,24 client=True, logger=None)25 mock1 = patch('cloudify_awssdk.common.decorators.aws_resource',26 mock_decorator)27 mock2 = patch('cloudify_awssdk.common.decorators.wait_for_status',28 mock_decorator)29 mock3 = patch('cloudify_awssdk.common.decorators.wait_for_delete',30 mock_decorator)31 mock1.start()32 mock2.start()33 mock3.start()34 reload(vpn_gateway)35 def test_class_properties(self):36 effect = self.get_client_error_exception(name='EC2 VPN '37 'Gateway Bucket')38 self.vpn_gateway.client = \39 self.make_client_function('describe_vpn_gateways',40 side_effect=effect)41 res = self.vpn_gateway.properties42 self.assertIsNone(res)43 value = {}44 self.vpn_gateway.client = \45 self.make_client_function('describe_vpn_gateways',46 return_value=value)47 res = self.vpn_gateway.properties48 self.assertIsNone(res)49 value = {VPNGATEWAYS: [{VPNGATEWAY_ID: 'test_name'}]}50 self.vpn_gateway.client = \51 self.make_client_function('describe_vpn_gateways',52 return_value=value)53 res = self.vpn_gateway.properties54 self.assertEqual(res[VPNGATEWAY_ID], 'test_name')55 def test_class_status(self):56 value = {}57 self.vpn_gateway.client = self.make_client_function('describe_vpn'58 '_gateways',59 return_value=value)60 res = self.vpn_gateway.status61 self.assertIsNone(res)62 value = {VPNGATEWAYS: [{VPNGATEWAY_ID: 'test_name',63 'State': 'available'}]}64 self.vpn_gateway.client = self.make_client_function('describe_vpn'65 '_gateways',66 return_value=value)67 res = self.vpn_gateway.status68 self.assertEqual(res, 'available')69 def test_class_create(self):70 value = {'VpnGateway': 'test'}71 self.vpn_gateway.client = \72 self.make_client_function('create_vpn_gateway',73 return_value=value)74 res = self.vpn_gateway.create(value)75 self.assertEqual(res['VpnGateway'], value['VpnGateway'])76 def test_class_delete(self):77 params = {}78 self.vpn_gateway.client = \79 self.make_client_function('delete_vpn_gateway')80 self.vpn_gateway.delete(params)81 self.assertTrue(self.vpn_gateway.client.delete_vpn_gateway82 .called)83 params = {'VpnGateway': 'vpn gateway'}84 self.vpn_gateway.delete(params)85 self.assertEqual(params['VpnGateway'], 'vpn gateway')86 def test_class_attach(self):87 value = {'VpcAttachment': {VPNGATEWAY_ID: 'vpn', VPC_ID: 'vpc'}}88 self.vpn_gateway.client = \89 self.make_client_function('attach_vpn_gateway',90 return_value=value)91 with patch('cloudify_awssdk.ec2.resources.vpn_gateway'92 '.EC2VPNGateway.attach'):93 res = self.vpn_gateway.attach(value)94 self.assertEqual(res[VPC_ID], value['VpcAttachment'][VPC_ID])95 def test_class_detach(self):96 params = {}97 self.vpn_gateway.client = \98 self.make_client_function('detach_vpn_gateway')99 self.vpn_gateway.detach(params)100 self.assertTrue(self.vpn_gateway.client.detach_vpn_gateway101 .called)102 params = {VPNGATEWAY_ID: 'vpn', VPC_ID: 'vpc'}103 self.vpn_gateway.delete(params)104 self.assertTrue(self.vpn_gateway.client.detach_vpn_gateway105 .called)106 def test_prepare(self):107 ctx = self.get_mock_ctx("VpnGateway")108 config = {VPNGATEWAY_ID: 'vpn gateway'}109 vpn_gateway.prepare(ctx, config)110 self.assertEqual(ctx.instance.runtime_properties['resource_config'],111 config)112 def test_create(self):113 ctx = self.get_mock_ctx("VpnGateway")114 config = {VPNGATEWAY_ID: 'vpn gateway'}115 self.vpn_gateway.resource_id = config[VPNGATEWAY_ID]116 iface = MagicMock()117 iface.create = self.mock_return({'VpnGateway': config})118 vpn_gateway.create(ctx=ctx, iface=iface, resource_config=config)119 self.assertEqual(self.vpn_gateway.resource_id,120 'vpn gateway')121 def test_attach(self):122 ctx = self.get_mock_ctx("VpnGateway")123 self.vpn_gateway.resource_id = 'vpn gateway'124 config = {VPC_ID: 'vpc', 'Type': type}125 iface = MagicMock()126 iface.attach = self.mock_return(config)127 vpn_gateway.attach(ctx, iface, config)128 self.assertEqual(self.vpn_gateway.resource_id,129 'vpn gateway')130 def test_attach_with_relationships(self):131 ctx = self.get_mock_ctx("VpnGateway", type_hierarchy=[VPC_TYPE])132 config = {VPNGATEWAY_ID: 'vpn gateway', 'Type': type}133 self.vpn_gateway.resource_id = config[VPNGATEWAY_ID]134 iface = MagicMock()135 iface.attach = self.mock_return(config)136 with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):137 vpn_gateway.attach(ctx, iface, config)138 self.assertEqual(self.vpn_gateway.resource_id,139 'vpn gateway')140 def test_delete(self):141 ctx = self.get_mock_ctx("VpnGateway")142 iface = MagicMock()143 vpn_gateway.delete(ctx=ctx, iface=iface, resource_config={})144 self.assertTrue(iface.delete.called)145 def test_detach(self):146 ctx = self.get_mock_ctx("VpnGateway")147 self.vpn_gateway.resource_id = 'vpn gateway'148 config = {VPC_ID: 'vpc'}149 iface = MagicMock()150 iface.detach = self.mock_return(config)151 vpn_gateway.detach(ctx, iface, config)152 self.assertEqual(self.vpn_gateway.resource_id,153 'vpn gateway')154 def test_detach_with_relationships(self):155 ctx = self.get_mock_ctx("VpnGateway", type_hierarchy=[VPC_TYPE])156 config = {VPNGATEWAY_ID: 'vpn gateway'}157 self.vpn_gateway.resource_id = config[VPNGATEWAY_ID]158 iface = MagicMock()159 iface.detach = self.mock_return(config)160 ctx.instance.runtime_properties['vpc_id'] = 'vpc'161 vpn_gateway.detach(ctx, iface, config)162 self.assertEqual(self.vpn_gateway.resource_id,163 'vpn gateway')164if __name__ == '__main__':...

Full Screen

Full Screen

virtual_private_gateways.py

Source:virtual_private_gateways.py Github

copy

Full Screen

...22 filters = filters_from_querystring(self.querystring)23 vpn_gateways = self.ec2_backend.get_all_vpn_gateways(filters)24 template = self.response_template(DESCRIBE_VPN_GATEWAYS_RESPONSE)25 return template.render(vpn_gateways=vpn_gateways)26 def detach_vpn_gateway(self):27 vpn_gateway_id = self._get_param("VpnGatewayId")28 vpc_id = self._get_param("VpcId")29 attachment = self.ec2_backend.detach_vpn_gateway(vpn_gateway_id, vpc_id)30 template = self.response_template(DETACH_VPN_GATEWAY_RESPONSE)31 return template.render(attachment=attachment)32CREATE_VPN_GATEWAY_RESPONSE = """33<CreateVpnGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">34 <requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>35 <vpnGateway>36 <vpnGatewayId>{{ vpn_gateway.id }}</vpnGatewayId>37 <state>available</state>38 <type>{{ vpn_gateway.type }}</type>39 <availabilityZone>us-east-1a</availabilityZone>40 <attachments/>41 <tagSet>42 {% for tag in vpn_gateway.get_tags() %}43 <item>...

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