def test_get_saved_policy(self): ''' Test if it return the current policy for the specified table/chain ''' self.assertEqual(iptables.get_saved_policy(table='filter', chain=None, conf_file=None, family='ipv4'), 'Error: Chain needs to be specified') with patch.object(iptables, '_parse_conf', MagicMock(return_value={'filter': {'INPUT': {'policy': True}}})): self.assertTrue(iptables.get_saved_policy(table='filter', chain='INPUT', conf_file=None, family='ipv4')) with patch.object(iptables, '_parse_conf', MagicMock(return_value={'filter': {'INPUT': {'policy1': True}}})): self.assertIsNone(iptables.get_saved_policy(table='filter', chain='INPUT', conf_file=None, family='ipv4'))
def test_get_saved_policy(self): """ Test if it return the current policy for the specified table/chain """ self.assertEqual( iptables.get_saved_policy(table="filter", chain=None, conf_file=None, family="ipv4"), "Error: Chain needs to be specified", ) with patch.object( iptables, "_parse_conf", MagicMock(return_value={"filter": { "INPUT": { "policy": True } }}), ): self.assertTrue( iptables.get_saved_policy(table="filter", chain="INPUT", conf_file=None, family="ipv4")) with patch.object( iptables, "_parse_conf", MagicMock( return_value={"filter": { "INPUT": { "policy1": True } }}), ): self.assertIsNone( iptables.get_saved_policy(table="filter", chain="INPUT", conf_file=None, family="ipv4"))