Best Python code snippet using tempest_python
tests_icmp_check.py
Source:tests_icmp_check.py
1import subprocess2from mock import patch3from cabot.cabotapp.models import (4 ICMPStatusCheck,5 Instance,6 Service,7)8from .tests_basic import LocalTestCase9class TestICMPCheckRun(LocalTestCase):10 def setUp(self):11 super(TestICMPCheckRun, self).setUp()12 self.instance = Instance.objects.create(13 name='Instance',14 address='1.2.3.4'15 )16 self.icmp_check = ICMPStatusCheck.objects.create(17 name='ICMP Check',18 created_by=self.user,19 importance=Service.CRITICAL_STATUS,20 )21 self.instance.status_checks.add(22 self.icmp_check)23 self.patch = patch('cabot.cabotapp.models.subprocess.check_output', autospec=True)24 self.mock_check_output = self.patch.start()25 def tearDown(self):26 self.patch.stop()27 super(TestICMPCheckRun, self).tearDown()28 def test_icmp_run_use_instance_address(self):29 self.icmp_check.run()30 args = ['ping', '-c', '1', u'1.2.3.4']31 self.mock_check_output.assert_called_once_with(args, shell=False, stderr=-2)32 def test_icmp_run_success(self):33 checkresults = self.icmp_check.statuscheckresult_set.all()34 self.assertEqual(len(checkresults), 0)35 self.icmp_check.run()36 checkresults = self.icmp_check.statuscheckresult_set.all()37 self.assertEqual(len(checkresults), 1)38 self.assertTrue(self.icmp_check.last_result().succeeded)39 def test_icmp_run_bad_address(self):40 self.mock_check_output.side_effect = subprocess.CalledProcessError(2, None, "ping: bad address")41 checkresults = self.icmp_check.statuscheckresult_set.all()42 self.assertEqual(len(checkresults), 0)43 self.icmp_check.run()44 checkresults = self.icmp_check.statuscheckresult_set.all()45 self.assertEqual(len(checkresults), 1)46 self.assertFalse(self.icmp_check.last_result().succeeded)47 def test_icmp_run_inacessible(self):48 self.mock_check_output.side_effect = subprocess.CalledProcessError(1, None, "packet loss")49 checkresults = self.icmp_check.statuscheckresult_set.all()50 self.assertEqual(len(checkresults), 0)51 self.icmp_check.run()52 checkresults = self.icmp_check.statuscheckresult_set.all()53 self.assertEqual(len(checkresults), 1)...
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!!