def test_chain_present(self): ''' Test to verify the chain is exist. ''' ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[True, False, False]) with patch.dict(nftables.__salt__, {"nftables.check_chain": mock}): ret.update({'comment': 'nftables salt chain is already' ' exist in filter table for ipv4'}) self.assertDictEqual(nftables.chain_present('salt'), ret) mock = MagicMock(side_effect=[True, '']) with patch.dict(nftables.__salt__, {"nftables.new_chain": mock}): ret.update({'changes': {'locale': 'salt'}, 'comment': 'nftables salt chain in filter' ' table create success for ipv4'}) self.assertDictEqual(nftables.chain_present('salt'), ret) ret.update({'changes': {}, 'comment': 'Failed to create salt chain' ' in filter table: for ipv4', 'result': False}) self.assertDictEqual(nftables.chain_present('salt'), ret)
def test_chain_present(self): ''' Test to verify the chain is exist. ''' ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[True, False, False]) with patch.dict(nftables.__salt__, {"nftables.check_chain": mock}): ret.update({'comment': 'nftables salt chain is already' ' exist in filter table for ipv4'}) self.assertDictEqual(nftables.chain_present('salt'), ret) mock = MagicMock(side_effect=[True, '']) with patch.dict(nftables.__salt__, {"nftables.new_chain": mock}): ret.update({'changes': {'locale': 'salt'}, 'comment': 'nftables salt chain in filter' ' table create success for ipv4'}) self.assertDictEqual(nftables.chain_present('salt'), ret) ret.update({'changes': {}, 'comment': 'Failed to create salt chain' ' in filter table: for ipv4', 'result': False}) self.assertDictEqual(nftables.chain_present('salt'), ret)
def test_chain_present(self): """ Test to verify the chain is exist. """ ret = {"name": "salt", "changes": {}, "result": True, "comment": ""} mock = MagicMock(side_effect=[ { "result": True, "comment": "" }, { "result": False, "comment": "" }, { "result": False, "comment": "" }, ]) with patch.dict(nftables.__salt__, {"nftables.check_chain": mock}): ret.update({ "comment": "nftables salt chain is already" " exist in filter table for ipv4" }) self.assertDictEqual(nftables.chain_present("salt"), ret) mock = MagicMock(side_effect=[ { "result": True, "comment": "" }, { "result": False, "comment": "" }, ]) with patch.dict(nftables.__salt__, {"nftables.new_chain": mock}): with patch.dict(nftables.__opts__, {"test": False}): ret.update({ "changes": { "locale": "salt" }, "comment": "nftables salt chain in filter" " table create success for ipv4", }) self.assertDictEqual(nftables.chain_present("salt"), ret) ret.update({ "changes": {}, "comment": "Failed to create salt chain" " in filter table: for ipv4", "result": False, }) self.assertDictEqual(nftables.chain_present("salt"), ret)