How to use create_metering_label_rule method in tempest

Best Python code snippet using tempest_python

test_neutron_metering.py

Source:test_neutron_metering.py Github

copy

Full Screen

...164 def setUp(self):165 super(MeteringRuleTest, self).setUp()166 self.mockclient = mock.Mock(spec=neutronclient.Client)167 self.patchobject(neutronclient, 'Client', return_value=self.mockclient)168 def create_metering_label_rule(self):169 self.mockclient.create_metering_label_rule.return_value = {170 'metering_label_rule': {'id': '5678'}171 }172 snippet = template_format.parse(metering_template)173 self.stack = utils.parse_stack(snippet)174 self.patchobject(self.stack['label'], 'FnGetRefId',175 return_value='1234')176 resource_defns = self.stack.t.resource_definitions(self.stack)177 return metering.MeteringRule(178 'rule', resource_defns['rule'], self.stack)179 def test_create(self):180 rsrc = self.create_metering_label_rule()181 scheduler.TaskRunner(rsrc.create)()182 self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)183 self.mockclient.create_metering_label_rule.assert_called_once_with({184 'metering_label_rule': {185 'metering_label_id': '1234',186 'remote_ip_prefix': '10.0.3.0/24',187 'direction': 'ingress',188 'excluded': False189 }190 })191 def test_create_failed(self):192 self.mockclient.create_metering_label_rule.side_effect = (193 exceptions.NeutronClientException())194 snippet = template_format.parse(metering_template)195 stack = utils.parse_stack(snippet)196 self.patchobject(stack['label'], 'FnGetRefId',197 return_value='1234')198 resource_defns = stack.t.resource_definitions(stack)199 rsrc = metering.MeteringRule(200 'rule', resource_defns['rule'], stack)201 error = self.assertRaises(exception.ResourceFailure,202 scheduler.TaskRunner(rsrc.create))203 self.assertEqual(204 'NeutronClientException: resources.rule: '205 'An unknown exception occurred.',206 six.text_type(error))207 self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)208 self.mockclient.create_metering_label_rule.assert_called_once_with({209 'metering_label_rule': {210 'metering_label_id': '1234',211 'remote_ip_prefix': '10.0.3.0/24',212 'direction': 'ingress',213 'excluded': False214 }215 })216 def test_delete(self):217 rsrc = self.create_metering_label_rule()218 self.mockclient.delete_metering_label_rule.return_value = None219 self.mockclient.show_metering_label_rule.side_effect = (220 exceptions.NeutronClientException(status_code=404))221 scheduler.TaskRunner(rsrc.create)()222 scheduler.TaskRunner(rsrc.delete)()223 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)224 self.mockclient.create_metering_label_rule.assert_called_once_with({225 'metering_label_rule': {226 'metering_label_id': '1234',227 'remote_ip_prefix': '10.0.3.0/24',228 'direction': 'ingress',229 'excluded': False230 }231 })232 self.mockclient.delete_metering_label_rule.assert_called_once_with(233 '5678')234 self.mockclient.show_metering_label_rule.assert_called_once_with(235 '5678')236 def test_delete_already_gone(self):237 rsrc = self.create_metering_label_rule()238 self.mockclient.delete_metering_label_rule.side_effect = (239 exceptions.NeutronClientException(status_code=404))240 scheduler.TaskRunner(rsrc.create)()241 scheduler.TaskRunner(rsrc.delete)()242 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)243 self.mockclient.create_metering_label_rule.assert_called_once_with({244 'metering_label_rule': {245 'metering_label_id': '1234',246 'remote_ip_prefix': '10.0.3.0/24',247 'direction': 'ingress',248 'excluded': False249 }250 })251 self.mockclient.delete_metering_label_rule.assert_called_once_with(252 '5678')253 self.mockclient.show_metering_label_rule.assert_not_called()254 def test_delete_failed(self):255 rsrc = self.create_metering_label_rule()256 self.mockclient.delete_metering_label_rule.side_effect = (257 exceptions.NeutronClientException(status_code=400))258 scheduler.TaskRunner(rsrc.create)()259 error = self.assertRaises(exception.ResourceFailure,260 scheduler.TaskRunner(rsrc.delete))261 self.assertEqual(262 'NeutronClientException: resources.rule: '263 'An unknown exception occurred.',264 six.text_type(error))265 self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)266 self.mockclient.create_metering_label_rule.assert_called_once_with({267 'metering_label_rule': {268 'metering_label_id': '1234',269 'remote_ip_prefix': '10.0.3.0/24',270 'direction': 'ingress',271 'excluded': False272 }273 })274 self.mockclient.delete_metering_label_rule.assert_called_once_with(275 '5678')276 self.mockclient.show_metering_label_rule.assert_not_called()277 def test_attribute(self):278 rsrc = self.create_metering_label_rule()279 self.mockclient.show_metering_label_rule.return_value = {280 'metering_label_rule': {281 'metering_label_id': '1234',282 'remote_ip_prefix': '10.0.3.0/24',283 'direction': 'ingress',284 'excluded': False285 }286 }287 scheduler.TaskRunner(rsrc.create)()288 self.assertEqual('10.0.3.0/24', rsrc.FnGetAtt('remote_ip_prefix'))289 self.assertEqual('ingress', rsrc.FnGetAtt('direction'))290 self.assertIs(False, rsrc.FnGetAtt('excluded'))291 self.mockclient.create_metering_label_rule.assert_called_once_with({292 'metering_label_rule': {...

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 tempest 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