def test_flush_chain(self): ''' Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified. ''' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertFalse(nftables.flush(table='filter', chain='input')) self.assertTrue(nftables.flush(table='filter', chain='input'))
def test_flush_chain(self): ''' Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified. ''' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}), \ patch('salt.modules.nftables.check_chain', MagicMock(return_value=True)), \ patch('salt.modules.nftables.check_table', MagicMock(return_value=True)): self.assertFalse(nftables.flush(table='filter', chain='input')) self.assertTrue(nftables.flush(table='filter', chain='input'))
def test_flush(self): ''' Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified. ''' ret = 'Error: table filter in family ipv4 does not exist' mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.flush(table='filter', chain='input'), ret) ret = 'Error: chain input in table filter in family ip does not exist' mock = MagicMock(return_value='table ip filter') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.flush(table='filter', chain='input'), ret)
def test_flush(self): """ Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified. """ ret = {"result": False, "comment": "Table filter in family ipv4 does not exist"} mock = MagicMock(return_value="") with patch.dict(nftables.__salt__, {"cmd.run": mock}): self.assertEqual(nftables.flush(table="filter", chain="input"), ret) ret = { "result": False, "comment": "Chain input in table filter in family ipv4 does not exist", } mock = MagicMock(return_value="table ip filter") with patch.dict(nftables.__salt__, {"cmd.run": mock}): self.assertEqual(nftables.flush(table="filter", chain="input"), ret)
def test_flush_chain(self): """ Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified. """ mock = MagicMock(side_effect=["1", ""]) with patch.dict(nftables.__salt__, {"cmd.run": mock}), patch( "salt.modules.nftables.check_chain", MagicMock(return_value={"result": True, "comment": ""}), ), patch( "salt.modules.nftables.check_table", MagicMock(return_value={"result": True, "comment": ""}), ): _expected = { "result": False, "comment": "Failed to flush rules from chain input in table filter in family ipv4.", } self.assertEqual(nftables.flush(table="filter", chain="input"), _expected) _expected = { "result": True, "comment": "Flushed rules from chain input in table filter in family ipv4.", } self.assertEqual(nftables.flush(table="filter", chain="input"), _expected)
def test_flush_chain(self): ''' Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified. ''' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}), \ patch('salt.modules.nftables.check_chain', MagicMock(return_value={'result': True, 'comment': ''})), \ patch('salt.modules.nftables.check_table', MagicMock(return_value={'result': True, 'comment': ''})): _expected = {'result': False, 'comment': 'Failed to flush rules from chain input in table filter in family ipv4.'} self.assertEqual(nftables.flush(table='filter', chain='input'), _expected) _expected = {'result': True, 'comment': 'Flushed rules from chain input in table filter in family ipv4.'} self.assertEqual(nftables.flush(table='filter', chain='input'), _expected)