def test_append(self): ''' Test if it append a rule to the specified table/chain. ''' with patch.object(iptables, '_has_option', MagicMock(return_value=True)), \ patch.object(iptables, 'check', MagicMock(return_value=False)): self.assertEqual( iptables.append(table='filter', chain=None, rule=None, family='ipv4'), 'Error: Chain needs to be specified') self.assertEqual( iptables.append(table='filter', chain='INPUT', rule=None, family='ipv4'), 'Error: Rule needs to be specified') _rule = 'm state --state RELATED,ESTABLISHED -j ACCEPT' mock = MagicMock(side_effect=['', 'SALT']) with patch.dict(iptables.__salt__, {'cmd.run': mock}): self.assertTrue( iptables.append(table='filter', chain='INPUT', rule=_rule, family='ipv4')) self.assertFalse( iptables.append(table='filter', chain='INPUT', rule=_rule, family='ipv4'))
def test_append(self): ''' Test if it append a rule to the specified table/chain. ''' self.assertEqual(iptables.append(table='filter', chain=None, rule=None, family='ipv4'), 'Error: Chain needs to be specified') self.assertEqual(iptables.append(table='filter', chain='INPUT', rule=None, family='ipv4'), 'Error: Rule needs to be specified') _rule = 'm state --state RELATED,ESTABLISHED -j ACCEPT' mock = MagicMock(side_effect=['', 'SALT']) with patch.dict(iptables.__salt__, {'cmd.run': mock}): self.assertTrue(iptables.append(table='filter', chain='INPUT', rule=_rule, family='ipv4')) self.assertFalse(iptables.append(table='filter', chain='INPUT', rule=_rule, family='ipv4'))
def test_append(self): """ Test if it append a rule to the specified table/chain. """ with patch.object(iptables, "_has_option", MagicMock(return_value=True)), patch.object( iptables, "check", MagicMock(return_value=False)): self.assertEqual( iptables.append(table="filter", chain=None, rule=None, family="ipv4"), "Error: Chain needs to be specified", ) self.assertEqual( iptables.append(table="filter", chain="INPUT", rule=None, family="ipv4"), "Error: Rule needs to be specified", ) _rule = "m state --state RELATED,ESTABLISHED -j ACCEPT" mock = MagicMock(side_effect=["", "SALT"]) with patch.dict(iptables.__salt__, {"cmd.run": mock}): self.assertTrue( iptables.append(table="filter", chain="INPUT", rule=_rule, family="ipv4")) self.assertFalse( iptables.append(table="filter", chain="INPUT", rule=_rule, family="ipv4"))