diff options
| author | Louis Baudoux <lba@odoo.com> | 2021-04-27 15:13:17 +0000 |
|---|---|---|
| committer | Louis Baudoux <lba@odoo.com> | 2021-04-27 15:13:17 +0000 |
| commit | f31f1972ff0e35deb3005ce160930b70ddc8e531 (patch) | |
| tree | eaa048c9e689bb4cfbdfb277312041ac720bda0a /addons/iap/tools | |
| parent | b0d1c4bfb3fc9120636c2891cdb43febff1c2334 (diff) | |
[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#63096
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Diffstat (limited to 'addons/iap/tools')
| -rw-r--r-- | addons/iap/tools/iap_tools.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/addons/iap/tools/iap_tools.py b/addons/iap/tools/iap_tools.py index da17972f0f1..86c42d6daef 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 + #---------------------------------------------------------- # Helpers for both clients and proxy #---------------------------------------------------------- |
