How to use create_metering_label method in tempest

Best Python code snippet using tempest_python

test_neutron_metering.py

Source:test_neutron_metering.py Github

copy

Full Screen

...42 def setUp(self):43 super(MeteringLabelTest, self).setUp()44 self.mockclient = mock.Mock(spec=neutronclient.Client)45 self.patchobject(neutronclient, 'Client', return_value=self.mockclient)46 def create_metering_label(self):47 self.mockclient.create_metering_label.return_value = {48 'metering_label': {'id': '1234'}49 }50 snippet = template_format.parse(metering_template)51 self.stack = utils.parse_stack(snippet)52 resource_defns = self.stack.t.resource_definitions(self.stack)53 return metering.MeteringLabel(54 'label', resource_defns['label'], self.stack)55 def test_create(self):56 rsrc = self.create_metering_label()57 scheduler.TaskRunner(rsrc.create)()58 self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)59 self.mockclient.create_metering_label.assert_called_once_with({60 'metering_label': {61 'name': 'TestLabel',62 'description': 'Description of TestLabel',63 'shared': True64 }65 })66 def test_create_failed(self):67 self.mockclient.create_metering_label.side_effect = (68 exceptions.NeutronClientException())69 snippet = template_format.parse(metering_template)70 stack = utils.parse_stack(snippet)71 resource_defns = stack.t.resource_definitions(stack)72 rsrc = metering.MeteringLabel(73 'label', resource_defns['label'], stack)74 error = self.assertRaises(exception.ResourceFailure,75 scheduler.TaskRunner(rsrc.create))76 self.assertEqual(77 'NeutronClientException: resources.label: '78 'An unknown exception occurred.',79 six.text_type(error))80 self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)81 self.mockclient.create_metering_label.assert_called_once_with({82 'metering_label': {83 'name': 'TestLabel',84 'description': 'Description of TestLabel',85 'shared': True86 }87 })88 def test_delete(self):89 rsrc = self.create_metering_label()90 self.mockclient.delete_metering_label.return_value = None91 self.mockclient.show_metering_label.side_effect = (92 exceptions.NeutronClientException(status_code=404))93 scheduler.TaskRunner(rsrc.create)()94 scheduler.TaskRunner(rsrc.delete)()95 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)96 self.mockclient.create_metering_label.assert_called_once_with({97 'metering_label': {98 'name': 'TestLabel',99 'description': 'Description of TestLabel',100 'shared': True101 }102 })103 self.mockclient.delete_metering_label.assert_called_once_with('1234')104 self.mockclient.show_metering_label.assert_called_once_with('1234')105 def test_delete_already_gone(self):106 rsrc = self.create_metering_label()107 self.mockclient.delete_metering_label.side_effect = (108 exceptions.NeutronClientException(status_code=404))109 scheduler.TaskRunner(rsrc.create)()110 scheduler.TaskRunner(rsrc.delete)()111 self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)112 self.mockclient.create_metering_label.assert_called_once_with({113 'metering_label': {114 'name': 'TestLabel',115 'description': 'Description of TestLabel',116 'shared': True117 }118 })119 self.mockclient.delete_metering_label.assert_called_once_with('1234')120 self.mockclient.show_metering_label.assert_not_called()121 def test_delete_failed(self):122 rsrc = self.create_metering_label()123 self.mockclient.delete_metering_label.side_effect = (124 exceptions.NeutronClientException(status_code=400))125 scheduler.TaskRunner(rsrc.create)()126 error = self.assertRaises(exception.ResourceFailure,127 scheduler.TaskRunner(rsrc.delete))128 self.assertEqual(129 'NeutronClientException: resources.label: '130 'An unknown exception occurred.',131 six.text_type(error))132 self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)133 self.mockclient.create_metering_label.assert_called_once_with({134 'metering_label': {135 'name': 'TestLabel',136 'description': 'Description of TestLabel',137 'shared': True138 }139 })140 self.mockclient.delete_metering_label.assert_called_once_with('1234')141 def test_attribute(self):142 rsrc = self.create_metering_label()143 self.mockclient.show_metering_label.return_value = {144 'metering_label': {145 'name': 'TestLabel',146 'description': 'Description of TestLabel',147 'shared': True148 }149 }150 scheduler.TaskRunner(rsrc.create)()151 self.assertEqual('TestLabel', rsrc.FnGetAtt('name'))152 self.assertEqual('Description of TestLabel',153 rsrc.FnGetAtt('description'))154 self.assertTrue(rsrc.FnGetAtt('shared'))155 self.mockclient.create_metering_label.assert_called_once_with({156 'metering_label': {...

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