How to use pre_run method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_win_firewall.py

Source:test_win_firewall.py Github

copy

Full Screen

1import pytest2import salt.utils.platform3from tests.support.case import ModuleCase4from tests.support.unit import skipIf5@skipIf(not salt.utils.platform.is_windows(), "Tests for only Windows")6@pytest.mark.windows_whitelisted7class FirewallTest(ModuleCase):8 """9 Validate windows firewall module10 """11 def _pre_firewall_status(self, pre_run):12 post_run = self.run_function("firewall.get_config")13 network = ["Domain", "Public", "Private"]14 # compare the status of the firewall before and after test15 # and re-enable or disable depending on status before test run16 for net in network:17 if post_run[net] != pre_run[net]:18 if pre_run[net]:19 self.assertTrue(self.run_function("firewall.enable", profile=net))20 else:21 self.assertTrue(self.run_function("firewall.disable", profile=net))22 @pytest.mark.destructive_test23 @pytest.mark.slow_test24 def test_firewall_get_config(self):25 """26 test firewall.get_config27 """28 pre_run = self.run_function("firewall.get_config")29 # ensure all networks are enabled then test status30 self.assertTrue(self.run_function("firewall.enable", profile="allprofiles"))31 ret = self.run_function("firewall.get_config")32 network = ["Domain", "Public", "Private"]33 for net in network:34 self.assertTrue(ret[net])35 self._pre_firewall_status(pre_run)36 @pytest.mark.destructive_test37 @pytest.mark.slow_test38 def test_firewall_disable(self):39 """40 test firewall.disable41 """42 pre_run = self.run_function("firewall.get_config")43 network = "Private"44 ret = self.run_function("firewall.get_config")[network]45 if not ret:46 self.assertTrue(self.run_function("firewall.enable", profile=network))47 self.assertTrue(self.run_function("firewall.disable", profile=network))48 ret = self.run_function("firewall.get_config")[network]49 self.assertFalse(ret)50 self._pre_firewall_status(pre_run)51 @pytest.mark.destructive_test52 @pytest.mark.slow_test53 def test_firewall_enable(self):54 """55 test firewall.enable56 """57 pre_run = self.run_function("firewall.get_config")58 network = "Private"59 ret = self.run_function("firewall.get_config")[network]60 if ret:61 self.assertTrue(self.run_function("firewall.disable", profile=network))62 self.assertTrue(self.run_function("firewall.enable", profile=network))63 ret = self.run_function("firewall.get_config")[network]64 self.assertTrue(ret)65 self._pre_firewall_status(pre_run)66 @pytest.mark.slow_test67 def test_firewall_get_rule(self):68 """69 test firewall.get_rule70 """71 rule = "Remote Event Log Management (NP-In)"72 ret = self.run_function("firewall.get_rule", [rule])73 checks = ["Private", "LocalPort", "RemotePort"]74 for check in checks:75 self.assertIn(check, ret[rule])76 @pytest.mark.destructive_test77 @pytest.mark.slow_test78 def test_firewall_add_delete_rule(self):79 """80 test firewall.add_rule and delete_rule81 """82 rule = "test rule"83 port = "8080"84 # test adding firewall rule85 add_rule = self.run_function("firewall.add_rule", [rule, port])86 ret = self.run_function("firewall.get_rule", [rule])87 self.assertIn(rule, ret[rule])88 self.assertIn(port, ret[rule])89 # test deleting firewall rule90 self.assertTrue(self.run_function("firewall.delete_rule", [rule, port]))91 ret = self.run_function("firewall.get_rule", [rule])92 self.assertNotIn(rule, ret)93 self.assertNotIn(port, ret)...

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