def test_delete(self): ''' Test to delete a rule to a chain ''' ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(return_value=[]) with patch.object(nftables, '_STATE_INTERNAL_KEYWORDS', mock): mock = MagicMock(return_value='a') with patch.dict(nftables.__salt__, {'nftables.build_rule': mock}): mock = MagicMock(side_effect=[False, True, True, True]) with patch.dict(nftables.__salt__, {'nftables.check': mock}): ret.update({'comment': 'nftables rule for salt' ' already absent for ipv4 (a)', 'result': True}) self.assertDictEqual(nftables.delete('salt', table='', chain=''), ret) with patch.dict(nftables.__opts__, {'test': True}): ret.update({'result': None, 'comment': 'nftables rule for salt needs' ' to be deleted for ipv4 (a)'}) self.assertDictEqual(nftables.delete('salt', table='', chain=''), ret) with patch.dict(nftables.__opts__, {'test': False}): mock = MagicMock(side_effect=[True, False]) with patch.dict(nftables.__salt__, {'nftables.delete': mock}): ret.update({'result': True, 'changes': {'locale': 'salt'}, 'comment': 'Delete nftables rule' ' for salt a'}) self.assertDictEqual(nftables.delete('salt', table='', chain='', position=''), ret) ret.update({'result': False, 'changes': {}, 'comment': 'Failed to delete nftables' ' rule for salt.\nAttempted rule was a' }) self.assertDictEqual(nftables.delete('salt', table='', chain='', position=''), ret)
def test_delete(): """ Test to delete a rule to a chain """ ret = {"name": "salt", "changes": {}, "result": None, "comment": ""} mock = MagicMock(return_value=[]) with patch.object(nftables, "_STATE_INTERNAL_KEYWORDS", mock): mock = MagicMock(return_value={ "result": True, "comment": "", "rule": "a" }) with patch.dict(nftables.__salt__, {"nftables.build_rule": mock}): mock = MagicMock(side_effect=[ { "result": False, "comment": "" }, { "result": True, "comment": "" }, { "result": True, "comment": "" }, { "result": True, "comment": "" }, ]) with patch.dict(nftables.__salt__, {"nftables.check": mock}): ret.update({ "comment": "nftables rule for salt already absent for ipv4 (a)", "result": True, }) assert nftables.delete("salt", table="", chain="") == ret with patch.dict(nftables.__opts__, {"test": True}): ret.update({ "result": None, "comment": "nftables rule for salt needs to be deleted for ipv4 (a)", }) assert nftables.delete("salt", table="", chain="") == ret with patch.dict(nftables.__opts__, {"test": False}): mock = MagicMock(side_effect=[ { "result": True, "comment": "" }, { "result": False, "comment": "" }, ]) with patch.dict(nftables.__salt__, {"nftables.delete": mock}): ret.update({ "result": True, "changes": { "locale": "salt" }, "comment": "Delete nftables rule for salt a", }) assert (nftables.delete("salt", table="", chain="", position="") == ret) ret.update({ "result": False, "changes": {}, "comment": "Failed to delete nftables rule for" " salt.\nAttempted rule was a", }) assert (nftables.delete("salt", table="", chain="", position="") == ret)