- split the mail_client_extension module onto two modules: 1) module mail_client_extension having mail/contact specific code, depends on iap and contacts only 2) module crm_mail_client_extension having crm specific code, depends on CRM and mail_client_extension. Purpose is to allow the user to use the mail_client_extension without needing to install CRM, this will also allow the usage of the mail connector in other modules without the need for CRM. - add the module_mail_client_extension field to the res_config_settings model of the base_setup module in order to enable the user to install the mail_client_extension module directly from the settings - move the crm_lead model from the mail_client_extension_module to the newly created crm_mail_client_extension_module, as this model is no longer needed by the mail_client_extension module because it no longer not implemants CRM functionality - move the iap_enrich_api model from the crm_iap_lead_enrich module onto the iap module as it is only related to contacts and not to CRM, this way it can be used in other modules such as the mail_client_extension module without the need for CRM module Task-2382870 UPG-PR: https://github.com/odoo/upgrade/pull/2156 COM-PR: https://github.com/odoo/odoo/pull/66139
52 lines
2.1 KiB
Python
52 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from contextlib import contextmanager
|
|
from functools import partial
|
|
from unittest.mock import patch
|
|
|
|
from odoo import exceptions
|
|
from odoo.addons.iap.tools import iap_tools
|
|
from odoo.addons.iap.models.iap_enrich_api import IapEnrichAPI
|
|
from odoo.tests import common
|
|
|
|
|
|
class MockIAPEnrich(common.BaseCase):
|
|
|
|
@contextmanager
|
|
def mockIAPEnrichGateway(self, default_data=None, email_data=None, sim_error=None, failing_emails=None):
|
|
|
|
def _contact_iap(local_endpoint, params):
|
|
sim_result = {
|
|
'name': 'Simulator INC',
|
|
'location': 'Simulator Street',
|
|
'city': 'SimCity',
|
|
'postal_code': '9876',
|
|
'country_code': 'BE',
|
|
'clearbit_id': 'idontknow',
|
|
'phone_numbers': ['+3269001122', '+32456001122'],
|
|
'twitter': 'testtwitter',
|
|
'facebook': 'testfacebook',
|
|
}
|
|
if default_data:
|
|
sim_result.update(default_data)
|
|
# mock single sms sending
|
|
if local_endpoint == '/iap/clearbit/1/lead_enrichment_email':
|
|
result = {}
|
|
for lead_id, email in params['domains'].items():
|
|
if sim_error and sim_error == 'credit':
|
|
raise iap_tools.InsufficientCreditError('InsufficientCreditError')
|
|
elif sim_error and sim_error == 'jsonrpc_exception':
|
|
raise exceptions.AccessError(
|
|
'The url that this service requested returned an error. Please contact the author of the app. The url it tried to contact was ' + local_endpoint
|
|
)
|
|
result[str(lead_id)] = dict(sim_result)
|
|
if email_data and email_data.get(email):
|
|
result[str(lead_id)].update(email_data[email])
|
|
return result
|
|
|
|
try:
|
|
with patch.object(IapEnrichAPI, '_contact_iap', side_effect=_contact_iap) as contact_iap_mock:
|
|
yield
|
|
finally:
|
|
pass
|