Best Python code snippet using localstack_python
test_networkacl.py
Source: test_networkacl.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.networkacl import EC2NetworkAcl, \17 NETWORKACLS, NETWORKACL_ID, ASSOCIATION_SUBNET_ID, \18 VPC_ID, VPC_TYPE, SUBNET_ID, SUBNET_TYPE, ASSOCIATION_ID19from mock import patch, MagicMock20from cloudify_awssdk.ec2.resources import networkacl21class TestEC2NetworkAcl(TestBase):22 def setUp(self):23 self.networkacl = EC2NetworkAcl("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(networkacl)29 def test_class_properties(self):30 effect = self.get_client_error_exception(name='EC2 Network Acl')31 self.networkacl.client = \32 self.make_client_function('describe_network_acls',33 side_effect=effect)34 res = self.networkacl.properties35 self.assertIsNone(res)36 value = {}37 self.networkacl.client = \38 self.make_client_function('describe_network_acls',39 return_value=value)40 res = self.networkacl.properties41 self.assertIsNone(res)42 value = {NETWORKACLS: [{NETWORKACL_ID: 'test_name'}]}43 self.networkacl.client = \44 self.make_client_function('describe_network_acls',45 return_value=value)46 res = self.networkacl.properties47 self.assertEqual(res[NETWORKACL_ID], 'test_name')48 def test_class_properties_by_filter(self):49 effect = self.get_client_error_exception(name='EC2 Network Acl')50 self.networkacl.client = \51 self.make_client_function('describe_network_acls',52 side_effect=effect)53 config = {SUBNET_ID: 'subnet'}54 res = self.networkacl.get_properties_by_filter(ASSOCIATION_SUBNET_ID,55 config[SUBNET_ID])56 self.assertIsNone(res)57 value = {}58 self.networkacl.client = \59 self.make_client_function('describe_network_acls',60 return_value=value)61 res = self.networkacl.get_properties_by_filter(ASSOCIATION_SUBNET_ID,62 config[SUBNET_ID])63 self.assertIsNone(res)64 value = {NETWORKACLS: [{NETWORKACL_ID: 'test_name'}]}65 self.networkacl.client = \66 self.make_client_function('describe_network_acls',67 return_value=value)68 res = self.networkacl.get_properties_by_filter(ASSOCIATION_SUBNET_ID,69 config[SUBNET_ID])70 self.assertEqual(res[NETWORKACL_ID], 'test_name')71 def test_class_create(self):72 value = {'NetworkAcl': 'test'}73 self.networkacl.client = \74 self.make_client_function('create_network_acl',75 return_value=value)76 res = self.networkacl.create(value)77 self.assertEqual(res['NetworkAcl'], value['NetworkAcl'])78 def test_class_delete(self):79 params = {}80 self.networkacl.client = self.make_client_function('delete'81 '_network_acl')82 self.networkacl.delete(params)83 self.assertTrue(self.networkacl.client.delete_network_acl84 .called)85 params = {'NetworkAcl': 'network acls'}86 self.networkacl.delete(params)87 self.assertEqual(params['NetworkAcl'], 'network acls')88 def test_class_attach(self):89 value = {ASSOCIATION_ID: 'test'}90 self.networkacl.client = \91 self.make_client_function('replace_network_acl_association',92 return_value=value)93 res = self.networkacl.attach(value)94 self.assertEqual(res[ASSOCIATION_ID], value[ASSOCIATION_ID])95 def test_class_detach(self):96 params = {}97 self.networkacl.client = \98 self.make_client_function('replace_network_acl_association')99 self.networkacl.detach(params)100 self.assertTrue(self.networkacl.client.replace_network_acl_association101 .called)102 ctx = self.get_mock_ctx("NetworkAcl")103 ctx.instance.runtime_properties['association_id'] = 'association_id'104 params = {}105 self.networkacl.delete(params)106 self.assertTrue(self.networkacl.client.replace_network_acl_association107 .called)108 def test_prepare(self):109 ctx = self.get_mock_ctx("NetworkAcl")110 config = {NETWORKACL_ID: 'network acl'}111 networkacl.prepare(ctx, config)112 self.assertEqual(ctx.instance.runtime_properties['resource_config'],113 config)114 def test_create(self):115 ctx = self.get_mock_ctx("NetworkAcl")116 config = {NETWORKACL_ID: 'network acl', VPC_ID: 'vpc'}117 self.networkacl.resource_id = config[NETWORKACL_ID]118 iface = MagicMock()119 iface.create = self.mock_return({'NetworkAcl': config})120 networkacl.create(ctx=ctx, iface=iface, resource_config=config)121 self.assertEqual(self.networkacl.resource_id,122 'network acl')123 def test_create_with_relationships(self):124 ctx = self.get_mock_ctx("NetworkAcl", type_hierarchy=[VPC_TYPE])125 config = {}126 self.networkacl.resource_id = 'networkacl'127 iface = MagicMock()128 iface.create = self.mock_return({'NetworkAcl': config})129 with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):130 networkacl.create(ctx=ctx, iface=iface, resource_config=config)131 self.assertEqual(self.networkacl.resource_id,132 'networkacl')133 def test_attach(self):134 ctx = self.get_mock_ctx("NetworkAcl")135 self.networkacl.resource_id = 'network acl'136 config = {NETWORKACL_ID: 'network acl', SUBNET_ID: 'subnet'}137 iface = MagicMock()138 iface.attach = self.mock_return(config)139 networkacl.attach(ctx, iface, config)140 self.assertEqual(self.networkacl.resource_id,141 'network acl')142 def test_attach_with_relationships(self):143 ctx = self.get_mock_ctx("NetworkAcl", type_hierarchy=[SUBNET_TYPE])144 config = {}145 self.networkacl.resource_id = 'network acl'146 iface = MagicMock()147 iface.attach = self.mock_return(config)148 iface.resource_id = self.mock_return('network acl')149 with patch('cloudify_awssdk.common.utils.find_rel_by_node_type'):150 networkacl.attach(ctx, iface, config)151 self.assertEqual(self.networkacl.resource_id,152 'network acl')153 def test_delete(self):154 ctx = self.get_mock_ctx("NetworkAcl")155 iface = MagicMock()156 networkacl.delete(ctx=ctx, iface=iface, resource_config={})157 self.assertTrue(iface.delete.called)158 def test_detach(self):159 ctx = self.get_mock_ctx("NetworkAcl")160 self.networkacl.resource_id = 'network acl'161 ctx.instance.runtime_properties['association_id'] = 'association_id'162 ctx.instance.runtime_properties['default_acl_id'] = 'default_acl_id'163 iface = MagicMock()164 iface.detach = self.mock_return('new_association_id')165 networkacl.detach(ctx, iface, {})166 self.assertEqual(self.networkacl.resource_id,167 'network acl')168if __name__ == '__main__':...
test_ec2.py
Source: test_ec2.py
...75 assert r["VpcId"] == test_vpc["VpcId"]76 if r["RouteTableId"] == route_table["RouteTableId"]:77 found = True78 assert found79def test_describe_network_acls(test_vpc, network_acl):80 result = describe_network_acls(NetworkAclIds=[network_acl["NetworkAclId"]])81 assert len(result) == 182 assert result[0]["NetworkAclId"] == network_acl["NetworkAclId"]83 assert result[0]["VpcId"] == test_vpc["VpcId"]84 # Try with a filter:85 result = describe_network_acls(Filters=[{"Name": "vpc-id", "Values": [test_vpc["VpcId"]]}])86 # Moto returns 2:87 found = False88 for r in result:89 assert r["VpcId"] == test_vpc["VpcId"]90 if r["NetworkAclId"] == network_acl["NetworkAclId"]:91 found = True92 assert found93def test_describe_vpc_attribute(test_vpc):94 result = describe_vpc_attribute(VpcId=test_vpc["VpcId"], Attribute="enableDnsSupport")95 assert result["EnableDnsSupport"]96 result = describe_vpc_attribute(VpcId=test_vpc["VpcId"], Attribute="enableDnsHostnames")...
networkacl.py
Source: networkacl.py
...27 i_am_plural = 'Network ACLs'28 def __init__(self, accounts=None, debug=False):29 super(NetworkACL, self).__init__(accounts=accounts, debug=debug)30 @record_exception()31 def describe_network_acls(self, **kwargs):32 from security_monkey.common.sts_connect import connect33 conn = connect(kwargs['account_name'], 'boto3.ec2.client', region=kwargs['region'],34 assumed_role=kwargs['assumed_role'])35 networkacls_resp = self.wrap_aws_rate_limited_call(36 conn.describe_network_acls)37 networkacls = networkacls_resp.get('NetworkAcls', [])38 return networkacls39 def slurp(self):40 """41 :returns: item_list - list of network acls.42 :returns: exception_map - A dict where the keys are a tuple containing the43 location of the exception and the value is the actual exception44 """45 self.prep_for_slurp()46 @iter_account_region(index=self.index, accounts=self.accounts, service_name='ec2')47 def slurp_items(**kwargs):48 item_list = []49 exception_map = {}50 kwargs['exception_map'] = exception_map51 app.logger.debug("Checking {}/{}/{}".format(self.index,52 kwargs['account_name'], kwargs['region']))53 networkacls = self.describe_network_acls(**kwargs)54 if networkacls:55 for nacl in networkacls:56 nacl_id = nacl.get('NetworkAclId')57 if self.check_ignore_list(nacl_id):58 continue59 config = {60 'id': nacl_id,61 'vpc_id': nacl.get('VpcId'),62 'is_default': bool(nacl.get('IsDefault')),63 'entries': nacl.get('Entries'),64 'associations': nacl.get('Associations'),65 'tags': nacl.get('Tags')66 }67 item = NetworkACLItem(region=kwargs['region'],...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!