Best Python code snippet using avocado_python
service_unittest.py
Source:service_unittest.py
...152 _()153 def test_unknown_runlevel(self):154 self.assertRaises(ValueError,155 service.convert_systemd_target_to_runlevel, "unknown")156 def test_runlevels(self):157 assert service.convert_sysv_runlevel(0) == "poweroff.target"158 assert service.convert_sysv_runlevel(1) == "rescue.target"159 assert service.convert_sysv_runlevel(2) == "multi-user.target"160 assert service.convert_sysv_runlevel(5) == "graphical.target"161 assert service.convert_sysv_runlevel(6) == "reboot.target"162class TestSysVInitServiceManager(TestServiceManager):163 def setUp(self):164 self.run_mock = MagicMock()165 self.init_name = "init"166 self.service_manager = super(TestSysVInitServiceManager,167 self).get_service_manager_from_init_and_run(self.init_name,168 self.run_mock)169 def test_list(self):170 list_result_mock = MagicMock(exit_status=0,171 stdout="sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off\n"172 "vsftpd 0:off 1:off 2:off 3:off 4:off 5:on 6:off\n"173 "xinetd based services:\n"174 " amanda: off\n"175 " chargen-dgram: on\n")176 run_mock = MagicMock(return_value=list_result_mock)177 service_manager = super(TestSysVInitServiceManager,178 self).get_service_manager_from_init_and_run(self.init_name,179 run_mock)180 list_result = service_manager.list(ignore_status=False)181 assert run_mock.call_args[0][182 0] == "chkconfig --list"183 assert list_result == {'sshd': {0: "off", 1: "off", 2: "off", 3: "off", 4: "off", 5: "off", 6: "off"},184 'vsftpd': {0: "off", 1: "off", 2: "off", 3: "off", 4: "off", 5: "on", 6: "off"},185 'xinetd': {'amanda': "off", 'chargen-dgram': "on"}}186 def test_enable(self):187 service = "lldpad"188 self.service_manager.enable(service)189 assert self.run_mock.call_args[0][0] == "chkconfig lldpad on"190 def test_unknown_runlevel(self):191 self.assertRaises(ValueError,192 service.convert_sysv_runlevel, "unknown")193 def test_runlevels(self):194 assert service.convert_systemd_target_to_runlevel(195 "poweroff.target") == '0'196 assert service.convert_systemd_target_to_runlevel(197 "rescue.target") == 's'198 assert service.convert_systemd_target_to_runlevel(199 "multi-user.target") == '3'200 assert service.convert_systemd_target_to_runlevel(201 "graphical.target") == '5'202 assert service.convert_systemd_target_to_runlevel(203 "reboot.target") == '6'204if __name__ == '__main__':...
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!!