How to use list_firewall_rules method in localstack

Best Python code snippet using localstack_python

fwaas_tests.py

Source:fwaas_tests.py Github

copy

Full Screen

...52 def test_rule_list(self):53 exp_rules = self.fw_rules.list()54 api_rules = {'firewall_rules': self.api_fw_rules.list()}55 api_policies = {'firewall_policies': self.api_fw_policies.list()}56 neutronclient.list_firewall_rules().AndReturn(api_rules)57 neutronclient.list_firewall_policies().AndReturn(api_policies)58 self.mox.ReplayAll()59 ret_val = api.fwaas.rule_list(self.request)60 for (v, d) in zip(ret_val, exp_rules):61 self._assert_rule_return_value(v, d)62 @test.create_stubs({neutronclient: ('list_firewall_rules',63 'list_firewall_policies')})64 def test_rule_list_for_tenant(self):65 tenant_id = self.request.user.project_id66 exp_rules = self.fw_rules.list()67 api_rules = {'firewall_rules': self.api_fw_rules.list()}68 api_policies = {'firewall_policies': self.api_fw_policies.list()}69 neutronclient.list_firewall_rules(70 tenant_id=tenant_id,71 shared=False).AndReturn({'firewall_rules': []})72 neutronclient.list_firewall_rules(shared=True) \73 .AndReturn(api_rules)74 neutronclient.list_firewall_policies().AndReturn(api_policies)75 self.mox.ReplayAll()76 ret_val = api.fwaas.rule_list_for_tenant(self.request, tenant_id)77 for (v, d) in zip(ret_val, exp_rules):78 self._assert_rule_return_value(v, d)79 @test.create_stubs({neutronclient: ('show_firewall_rule',80 'show_firewall_policy')})81 def test_rule_get(self):82 exp_rule = self.fw_rules.first()83 ret_dict = {'firewall_rule': self.api_fw_rules.first()}84 policy_dict = {'firewall_policy': self.api_fw_policies.first()}85 neutronclient.show_firewall_rule(exp_rule.id).AndReturn(ret_dict)86 neutronclient.show_firewall_policy(87 exp_rule.firewall_policy_id).AndReturn(policy_dict)88 self.mox.ReplayAll()89 ret_val = api.fwaas.rule_get(self.request, exp_rule.id)90 self._assert_rule_return_value(ret_val, exp_rule)91 @test.create_stubs({neutronclient: ('update_firewall_rule',)})92 def test_rule_update(self):93 rule = self.fw_rules.first()94 rule_dict = self.api_fw_rules.first()95 rule.name = 'new name'96 rule.description = 'new desc'97 rule.protocol = 'icmp'98 rule.action = 'deny'99 rule.shared = True100 rule.enabled = False101 rule_dict['name'] = 'new name'102 rule_dict['description'] = 'new desc'103 rule_dict['protocol'] = 'icmp'104 rule_dict['action'] = 'deny'105 rule_dict['shared'] = True106 rule_dict['enabled'] = False107 form_data = {'name': rule.name,108 'description': rule.description,109 'protocol': rule.protocol,110 'action': rule.action,111 'shared': rule.shared,112 'enabled': rule.enabled113 }114 form_dict = {'firewall_rule': form_data}115 ret_dict = {'firewall_rule': rule_dict}116 neutronclient.update_firewall_rule(117 rule.id, form_dict).AndReturn(ret_dict)118 self.mox.ReplayAll()119 ret_val = api.fwaas.rule_update(self.request,120 rule.id, **form_data)121 self.assertIsInstance(ret_val, api.fwaas.Rule)122 self.assertEqual(rule.name, ret_val.name)123 self.assertTrue(ret_val.id)124 @test.create_stubs({neutronclient: ('create_firewall_policy', )})125 def test_policy_create(self):126 policy1 = self.fw_policies.first()127 policy1_dict = self.api_fw_policies.first()128 form_data = {'name': policy1.name,129 'description': policy1.description,130 'firewall_rules': policy1.firewall_rules,131 'shared': policy1.shared,132 'audited': policy1.audited133 }134 form_dict = {'firewall_policy': form_data}135 ret_dict = {'firewall_policy': policy1_dict}136 neutronclient.create_firewall_policy(form_dict).AndReturn(ret_dict)137 self.mox.ReplayAll()138 ret_val = api.fwaas.policy_create(self.request, **form_data)139 self.assertIsInstance(ret_val, api.fwaas.Policy)140 self.assertEqual(policy1.name, ret_val.name)141 self.assertTrue(ret_val.id)142 def _assert_policy_return_value(self, ret_val, exp_policy):143 self.assertIsInstance(ret_val, api.fwaas.Policy)144 self.assertEqual(exp_policy.name, ret_val.name)145 self.assertTrue(ret_val.id)146 self.assertEqual(len(exp_policy.firewall_rules), len(ret_val.rules))147 self.assertEqual(len(exp_policy.firewall_rules),148 len(ret_val.firewall_rules))149 for (r, exp_r) in zip(ret_val.rules, exp_policy.rules):150 self.assertEqual(exp_r.id, r.id)151 @test.create_stubs({neutronclient: ('list_firewall_policies',152 'list_firewall_rules')})153 def test_policy_list(self):154 exp_policies = self.fw_policies.list()155 policies_dict = {'firewall_policies': self.api_fw_policies.list()}156 rules_dict = {'firewall_rules': self.api_fw_rules.list()}157 neutronclient.list_firewall_policies().AndReturn(policies_dict)158 neutronclient.list_firewall_rules().AndReturn(rules_dict)159 self.mox.ReplayAll()160 ret_val = api.fwaas.policy_list(self.request)161 for (v, d) in zip(ret_val, exp_policies):162 self._assert_policy_return_value(v, d)163 @test.create_stubs({neutronclient: ('list_firewall_policies',164 'list_firewall_rules')})165 def test_policy_list_for_tenant(self):166 tenant_id = self.request.user.project_id167 exp_policies = self.fw_policies.list()168 policies_dict = {'firewall_policies': self.api_fw_policies.list()}169 rules_dict = {'firewall_rules': self.api_fw_rules.list()}170 neutronclient.list_firewall_policies(171 tenant_id=tenant_id,172 shared=False).AndReturn({'firewall_policies': []})173 neutronclient.list_firewall_policies(174 shared=True).AndReturn(policies_dict)175 neutronclient.list_firewall_rules().AndReturn(rules_dict)176 self.mox.ReplayAll()177 ret_val = api.fwaas.policy_list_for_tenant(self.request, tenant_id)178 for (v, d) in zip(ret_val, exp_policies):179 self._assert_policy_return_value(v, d)180 @test.create_stubs({neutronclient: ('show_firewall_policy',181 'list_firewall_rules')})182 def test_policy_get(self):183 exp_policy = self.fw_policies.first()184 policy_dict = self.api_fw_policies.first()185 # The first two rules are associated with the first policy.186 api_rules = self.api_fw_rules.list()[:2]187 ret_dict = {'firewall_policy': policy_dict}188 neutronclient.show_firewall_policy(exp_policy.id).AndReturn(ret_dict)189 filters = {'firewall_policy_id': exp_policy.id}190 ret_dict = {'firewall_rules': api_rules}191 neutronclient.list_firewall_rules(**filters).AndReturn(ret_dict)192 self.mox.ReplayAll()193 ret_val = api.fwaas.policy_get(self.request, exp_policy.id)194 self._assert_policy_return_value(ret_val, exp_policy)195 @test.create_stubs({neutronclient: ('show_firewall_policy',)})196 def test_policy_get_no_rule(self):197 # 2nd policy is not associated with any rules.198 exp_policy = self.fw_policies.list()[1]199 policy_dict = self.api_fw_policies.list()[1]200 ret_dict = {'firewall_policy': policy_dict}201 neutronclient.show_firewall_policy(exp_policy.id).AndReturn(ret_dict)202 self.mox.ReplayAll()203 ret_val = api.fwaas.policy_get(self.request, exp_policy.id)204 self.assertIsInstance(ret_val, api.fwaas.Policy)205 self.assertEqual(exp_policy.name, ret_val.name)...

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