From 60b89987ec8cfaa472cc76c7087d0dbbc93463aa Mon Sep 17 00:00:00 2001 From: Louis Baudoux Date: Tue, 27 Apr 2021 15:13:17 +0000 Subject: [PATCH] [IMP] iap: mock IAP jsonrpc to avoid errors/spam of the real servers Before this commit, some requests could be sent to the actual IAP servers during testing. These calls weren't always mocked as many of these requests are sent in background while performing usual tasks such as creating a bill. Now, any call to the function iap_jsonrpc during testing will result in an AccessError. closes odoo/odoo#70925 X-original-commit: f31f1972ff0e35deb3005ce160930b70ddc8e531 Signed-off-by: Christophe Monniez (moc) --- addons/iap/tools/iap_tools.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/addons/iap/tools/iap_tools.py b/addons/iap/tools/iap_tools.py index ed89d1f9246..9d8e4dc9a53 100644 --- a/addons/iap/tools/iap_tools.py +++ b/addons/iap/tools/iap_tools.py @@ -6,14 +6,34 @@ import logging import json import requests import uuid +from unittest.mock import patch from odoo import exceptions, _ +from odoo.tests.common import BaseCase from odoo.tools import pycompat _logger = logging.getLogger(__name__) DEFAULT_ENDPOINT = 'https://iap.odoo.com' + +# We need to mock iap_jsonrpc during tests as we don't want to perform real calls to RPC endpoints +def iap_jsonrpc_mocked(*args, **kwargs): + raise exceptions.AccessError("Unavailable during tests.") + + +iap_patch = patch('odoo.addons.iap.tools.iap_tools.iap_jsonrpc', iap_jsonrpc_mocked) + + +def setUp(self): + old_setup_func(self) + iap_patch.start() + self.addCleanup(iap_patch.stop) + + +old_setup_func = BaseCase.setUp +BaseCase.setUp = setUp + #---------------------------------------------------------- # Tools globals #----------------------------------------------------------