| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
from odoo.addons.crm.tests.common import TestCrmCommon |
| 5 |
from odoo.addons.iap.tests.common import MockIAPEnrich |
| 6 |
from odoo.tests.common import users |
| 7 |
|
| 8 |
|
| 9 |
class TestLeadEnrich(TestCrmCommon, MockIAPEnrich): |
| 10 |
|
| 11 |
@classmethod |
| 12 |
def setUpClass(cls): |
| 13 |
super(TestLeadEnrich, cls).setUpClass() |
| 14 |
cls.registry_enter_test_mode_cls() |
| 15 |
|
| 16 |
cls.leads = cls.env['crm.lead'] |
| 17 |
for x in range(0, 4): |
| 18 |
cls.leads += cls.env['crm.lead'].create({ |
| 19 |
'name': 'Test %s' % x, |
| 20 |
'email_from': 'test_mail_%[email protected]' % x |
| 21 |
}) |
| 22 |
|
| 23 |
@users('user_sales_manager') |
| 24 |
def test_enrich_internals(self): |
| 25 |
leads = self.env['crm.lead'].browse(self.leads.ids) |
| 26 |
leads[0].write({'partner_name': 'Already set', 'email_from': 'test@test1'}) |
| 27 |
leads.flush_recordset() |
| 28 |
with self.mockIAPEnrichGateway(email_data={'test1': {'country_code': 'AU', 'state_code': 'NSW'}}): |
| 29 |
leads.iap_enrich() |
| 30 |
|
| 31 |
leads.flush_recordset() |
| 32 |
self.assertEqual(leads[0].partner_name, 'Already set') |
| 33 |
self.assertEqual(leads[0].country_id, self.env.ref('base.au')) |
| 34 |
self.assertEqual(leads[0].state_id, self.env.ref('base.state_au_2')) |
| 35 |
for lead in leads[1:]: |
| 36 |
self.assertEqual(lead.partner_name, 'Simulator INC') |
| 37 |
for lead in leads: |
| 38 |
self.assertEqual(lead.street, 'Simulator Street') |
| 39 |
|
| 40 |
@users('user_sales_manager') |
| 41 |
def test_enrich_error_jsonrpc_exception(self): |
| 42 |
leads = self.env['crm.lead'].browse(self.leads.ids) |
| 43 |
with self.mockIAPEnrichGateway(sim_error='jsonrpc_exception'): |
| 44 |
leads.iap_enrich() |
| 45 |
|
| 46 |
for lead in leads: |
| 47 |
self.assertEqual(lead.street, False) |
| 48 |
|
| 49 |
def test_lead_enrich_auto_setting(self): |
| 50 |
cron = self.env.ref('crm_iap_enrich.ir_cron_lead_enrichment') |
| 51 |
|
| 52 |
config = self.env['res.config.settings'].create({ |
| 53 |
'lead_enrich_auto': 'manual', |
| 54 |
}) |
| 55 |
config.execute() |
| 56 |
self.assertFalse(cron.active) |
| 57 |
|
| 58 |
config.write({'lead_enrich_auto': 'auto'}) |
| 59 |
config.execute() |
| 60 |
self.assertTrue(cron.active) |