Best Python code snippet using tempest_python
test_volume_host.py
Source:test_volume_host.py
1#2# Licensed under the Apache License, Version 2.0 (the "License"); you may3# not use this file except in compliance with the License. You may obtain4# a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the11# License for the specific language governing permissions and limitations12# under the License.13#14from openstackclient.tests.unit.volume.v2 import fakes as host_fakes15from openstackclient.volume.v2 import volume_host16class TestVolumeHost(host_fakes.TestVolume):17 def setUp(self):18 super(TestVolumeHost, self).setUp()19 self.host_mock = self.app.client_manager.volume.services20 self.host_mock.reset_mock()21class TestVolumeHostSet(TestVolumeHost):22 service = host_fakes.FakeService.create_one_service()23 def setUp(self):24 super(TestVolumeHostSet, self).setUp()25 self.host_mock.freeze_host.return_value = None26 self.host_mock.thaw_host.return_value = None27 # Get the command object to mock28 self.cmd = volume_host.SetVolumeHost(self.app, None)29 def test_volume_host_set_nothing(self):30 arglist = [31 self.service.host,32 ]33 verifylist = [34 ('host', self.service.host),35 ]36 parsed_args = self.check_parser(self.cmd, arglist, verifylist)37 result = self.cmd.take_action(parsed_args)38 self.host_mock.freeze_host.assert_not_called()39 self.host_mock.thaw_host.assert_not_called()40 self.assertIsNone(result)41 def test_volume_host_set_enable(self):42 arglist = [43 '--enable',44 self.service.host,45 ]46 verifylist = [47 ('enable', True),48 ('host', self.service.host),49 ]50 parsed_args = self.check_parser(self.cmd, arglist, verifylist)51 result = self.cmd.take_action(parsed_args)52 self.host_mock.thaw_host.assert_called_with(self.service.host)53 self.host_mock.freeze_host.assert_not_called()54 self.assertIsNone(result)55 def test_volume_host_set_disable(self):56 arglist = [57 '--disable',58 self.service.host,59 ]60 verifylist = [61 ('disable', True),62 ('host', self.service.host),63 ]64 parsed_args = self.check_parser(self.cmd, arglist, verifylist)65 result = self.cmd.take_action(parsed_args)66 self.host_mock.freeze_host.assert_called_with(self.service.host)67 self.host_mock.thaw_host.assert_not_called()68 self.assertIsNone(result)69class TestVolumeHostFailover(TestVolumeHost):70 service = host_fakes.FakeService.create_one_service()71 def setUp(self):72 super(TestVolumeHostFailover, self).setUp()73 self.host_mock.failover_host.return_value = None74 # Get the command object to mock75 self.cmd = volume_host.FailoverVolumeHost(self.app, None)76 def test_volume_host_failover(self):77 arglist = [78 '--volume-backend', 'backend_test',79 self.service.host,80 ]81 verifylist = [82 ('volume_backend', 'backend_test'),83 ('host', self.service.host),84 ]85 parsed_args = self.check_parser(self.cmd, arglist, verifylist)86 result = self.cmd.take_action(parsed_args)87 self.host_mock.failover_host.assert_called_with(88 self.service.host, 'backend_test')...
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!!