Best Python code snippet using localstack_python
test_dhcp.py
Source:test_dhcp.py
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.dhcp import EC2DHCPOptions, \17 DHCPOPTIONS, DHCPOPTIONS_ID, \18 VPC_ID, VPC_TYPE19from mock import patch, MagicMock20from cloudify_awssdk.ec2.resources import dhcp21class TestEC2DHCPOptions(TestBase):22 def setUp(self):23 self.dhcp = EC2DHCPOptions("ctx_node", resource_id=True,24 client=True, logger=None)25 mock1 = patch('cloudify_awssdk.common.decorators.aws_resource',26 mock_decorator)27 mock1.start()28 reload(dhcp)29 def test_class_properties(self):30 effect = self.get_client_error_exception(name='EC2 Dhcp Options')31 self.dhcp.client = \32 self.make_client_function('describe_dhcp_options',33 side_effect=effect)34 res = self.dhcp.properties35 self.assertIsNone(res)36 value = {}37 self.dhcp.client = \38 self.make_client_function('describe_dhcp_options',39 return_value=value)40 res = self.dhcp.properties41 self.assertIsNone(res)42 value = {DHCPOPTIONS: [{DHCPOPTIONS_ID: 'test_name'}]}43 self.dhcp.client = \44 self.make_client_function('describe_dhcp_options',45 return_value=value)46 res = self.dhcp.properties47 self.assertEqual(res[DHCPOPTIONS_ID], 'test_name')48 def test_class_create(self):49 value = {DHCPOPTIONS: 'test'}50 self.dhcp.client = \51 self.make_client_function('create_dhcp_options',52 return_value=value)53 res = self.dhcp.create(value)54 self.assertEqual(res[DHCPOPTIONS], value[DHCPOPTIONS])55 def test_class_delete(self):56 params = {}57 self.dhcp.client = self.make_client_function('delete_dhcp_options')58 self.dhcp.delete(params)59 self.assertTrue(self.dhcp.client.delete_dhcp_options60 .called)61 params = {DHCPOPTIONS: 'dhcp'}62 self.dhcp.delete(params)63 self.assertEqual(params[DHCPOPTIONS], 'dhcp')64 def test_class_attach(self):65 value = {'VpcAttachment': {DHCPOPTIONS_ID: 'dhcp',66 VPC_ID: 'vpc'}}67 self.dhcp.client = \68 self.make_client_function('associate_dhcp_options',69 return_value=True)70 with patch('cloudify_awssdk.ec2.resources.dhcp'71 '.EC2DHCPOptions.attach'):72 res = self.dhcp.attach(value)73 self.assertEqual(True, res)74 def test_class_detach(self):75 params = {}76 self.dhcp.client = \77 self.make_client_function('associate_dhcp_options')78 self.dhcp.detach(params)79 self.assertTrue(self.dhcp.client.associate_dhcp_options80 .called)81 params = {DHCPOPTIONS_ID: 'dhcp', VPC_ID: 'vpc'}82 self.dhcp.delete(params)83 self.assertTrue(self.dhcp.client.associate_dhcp_options84 .called)85 def test_prepare(self):86 ctx = self.get_mock_ctx(DHCPOPTIONS)87 config = {DHCPOPTIONS_ID: 'dhcp'}88 dhcp.prepare(ctx, config)89 self.assertEqual(ctx.instance.runtime_properties['resource_config'],90 config)91 def test_create(self):92 ctx = self.get_mock_ctx(DHCPOPTIONS)93 config = {DHCPOPTIONS_ID: 'dhcp'}94 self.dhcp.resource_id = config[DHCPOPTIONS_ID]95 iface = MagicMock()96 iface.create = self.mock_return({DHCPOPTIONS: config})97 dhcp.create(ctx, iface, config)98 self.assertEqual(self.dhcp.resource_id,99 'dhcp')100 def test_attach(self):101 ctx = self.get_mock_ctx(DHCPOPTIONS)102 self.dhcp.resource_id = 'dhcp'103 config = {VPC_ID: 'vpc',104 'DhcpConfigurations': {'Key': 'domain-name',105 'Value': ['example.com']}}106 iface = MagicMock()107 iface.attach = self.mock_return(config)108 dhcp.attach(ctx, iface, config)109 self.assertEqual(self.dhcp.resource_id,110 'dhcp')111 def test_attach_with_relationships(self):112 ctx = self.get_mock_ctx(DHCPOPTIONS, type_hierarchy=[VPC_TYPE])113 config = {DHCPOPTIONS_ID: 'dhcp',114 'DhcpConfigurations': {'Key': 'domain-name',115 'Value': ['example.com']}}116 self.dhcp.resource_id = config[DHCPOPTIONS_ID]117 iface = MagicMock()118 iface.attach = self.mock_return(config)119 with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):120 dhcp.attach(ctx, iface, config)121 self.assertEqual(self.dhcp.resource_id,122 'dhcp')123 def test_delete(self):124 ctx = self.get_mock_ctx(DHCPOPTIONS)125 iface = MagicMock()126 dhcp.delete(ctx, iface, {})127 self.assertTrue(iface.delete.called)128 def test_detach(self):129 ctx = self.get_mock_ctx(DHCPOPTIONS)130 self.dhcp.resource_id = 'dhcp'131 config = {VPC_ID: 'vpc'}132 iface = MagicMock()133 iface.detach = self.mock_return(config)134 dhcp.detach(ctx, iface, config)135 self.assertEqual(self.dhcp.resource_id,136 'dhcp')137 def test_detach_with_relationships(self):138 ctx = self.get_mock_ctx(DHCPOPTIONS, type_hierarchy=[VPC_TYPE])139 config = {DHCPOPTIONS_ID: 'dhcp'}140 self.dhcp.resource_id = config[DHCPOPTIONS_ID]141 iface = MagicMock()142 iface.detach = self.mock_return(config)143 ctx.instance.runtime_properties['vpc_id'] = None144 with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):145 dhcp.detach(ctx, iface, config)146 self.assertEqual(self.dhcp.resource_id,147 'dhcp')148if __name__ == '__main__':...
awsops.py
Source:awsops.py
...19 return response20 def attach_internet_gateway(self, vpc_id, igw_id):21 """ Attach a given igw to a given vpc """22 pass23 def associate_dhcp_options(self, vpc_id, dhcp_options_id):24 """ Associate a given dhcp_options to a given vpc """25 response = self.ec2.associate_dhcp_options(26 DhcpOptionsId=dhcp_options_id,27 VpcId=vpc_id,28 )...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!