[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) <moc@odoo.com>
This commit is contained in:
@@ -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
|
||||
#----------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user