test_lead_mine.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import exceptions
  4. from odoo.addons.crm.tests.common import TestCrmCommon
  5. from odoo.addons.crm_iap_mine.tests.common import MockIAPReveal
  6. from odoo.tests.common import users
  7. class TestLeadMine(TestCrmCommon, MockIAPReveal):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestLeadMine, cls).setUpClass()
  11. cls.registry.enter_test_mode(cls.cr)
  12. cls.test_crm_tags = cls.env['crm.tag'].create([
  13. {'name': 'TestTag1'},
  14. {'name': 'TestTag2'}
  15. ])
  16. cls.test_request = cls.env['crm.iap.lead.mining.request'].create({
  17. 'contact_number': 3,
  18. 'error_type': False,
  19. 'lead_number': 3,
  20. 'lead_type': 'lead',
  21. 'name': 'Test Mine',
  22. 'search_type': 'people',
  23. 'state': 'draft',
  24. 'tag_ids': [(6, 0, cls.test_crm_tags.ids)],
  25. 'team_id': cls.sales_team_1.id,
  26. 'user_id': cls.user_sales_leads.id,
  27. })
  28. @classmethod
  29. def tearDownClass(cls):
  30. cls.registry.leave_test_mode()
  31. super().tearDownClass()
  32. @users('user_sales_manager')
  33. def test_mine_error_credit(self):
  34. mine_request = self.env['crm.iap.lead.mining.request'].browse(self.test_request.ids)
  35. with self.mock_IAP_mine(mine_request, sim_error='credit'):
  36. mine_request.action_submit()
  37. self.assertEqual(mine_request.error_type, 'credits')
  38. self.assertEqual(mine_request.state, 'error')
  39. @users('user_sales_manager')
  40. def test_mine_error_jsonrpc_exception(self):
  41. mine_request = self.env['crm.iap.lead.mining.request'].browse(self.test_request.ids)
  42. with self.assertRaises(exceptions.UserError):
  43. with self.mock_IAP_mine(mine_request, sim_error='jsonrpc_exception'):
  44. mine_request.action_submit()
  45. @users('user_sales_manager')
  46. def test_mine_error_no_result(self):
  47. mine_request = self.env['crm.iap.lead.mining.request'].browse(self.test_request.ids)
  48. with self.mock_IAP_mine(mine_request, sim_error='no_result'):
  49. mine_request.action_submit()
  50. self.assertEqual(mine_request.error_type, 'no_result')
  51. self.assertEqual(mine_request.state, 'draft')
  52. @users('user_sales_manager')
  53. def test_mine_wpeople(self):
  54. country_de = self.base_de
  55. state_de = self.de_state_st
  56. mine_request = self.env['crm.iap.lead.mining.request'].browse(self.test_request.ids)
  57. with self.mock_IAP_mine(mine_request, name_list=['Heinrich', 'Rivil', 'LidGen']):
  58. mine_request.action_submit()
  59. self.assertFalse(mine_request.error_type)
  60. self.assertEqual(mine_request.state, 'done')
  61. self.assertEqual(len(self._new_leads), 3, 'Number of leads should match mine request')
  62. for base_name in ['Heinrich', 'Rivil', 'LidGen']:
  63. lead = self._new_leads.filtered(lambda lead: lead.name == '%s GmbH' % base_name)
  64. self.assertTrue(bool(lead))
  65. # mine information
  66. self.assertEqual(lead.type, 'lead')
  67. self.assertEqual(lead.tag_ids, self.test_crm_tags)
  68. self.assertEqual(lead.team_id, self.sales_team_1)
  69. self.assertEqual(lead.user_id, self.user_sales_leads)
  70. # iap
  71. self.assertEqual(lead.reveal_id, '123_ClearbitID_%s' % base_name, 'Ensure reveal_id is set to clearbit ID')
  72. # clearbit information
  73. self.assertEqual(lead.contact_name, 'Contact %s 0' % base_name)
  74. self.assertEqual(lead.city, 'Mönchengladbach')
  75. self.assertEqual(lead.country_id, country_de)
  76. self.assertEqual(lead.email_from, 'test.contact.0@%s.example.com' % base_name,
  77. 'Lead email should be the one from first contact if search_type people is given')
  78. self.assertEqual(lead.function, 'Doing stuff')
  79. self.assertFalse(lead.partner_id)
  80. self.assertEqual(lead.partner_name, '%s GmbH legal_name' % base_name)
  81. self.assertEqual(lead.phone, '+4930499193937')
  82. self.assertEqual(lead.state_id, state_de)
  83. self.assertEqual(lead.street, 'Mennrather Str. 123456')
  84. self.assertEqual(lead.website, 'https://www.%s.de' % base_name)
  85. self.assertEqual(lead.zip, '41179')
  86. @users('user_sales_manager')
  87. def test_mine_wcompany(self):
  88. country_de = self.base_de
  89. state_de = self.de_state_st
  90. mine_request = self.env['crm.iap.lead.mining.request'].browse(self.test_request.ids)
  91. mine_request.write({'search_type': 'companies'})
  92. with self.mock_IAP_mine(mine_request, name_list=['Heinrich', 'Rivil', 'LidGen']):
  93. mine_request.action_submit()
  94. self.assertFalse(mine_request.error_type)
  95. self.assertEqual(mine_request.state, 'done')
  96. self.assertEqual(len(self._new_leads), 3, 'Number of leads should match mine request')
  97. for base_name in ['Heinrich', 'Rivil', 'LidGen']:
  98. lead = self._new_leads.filtered(lambda lead: lead.name == '%s GmbH' % base_name)
  99. self.assertTrue(bool(lead))
  100. # mine information
  101. self.assertEqual(lead.type, 'lead')
  102. self.assertEqual(lead.tag_ids, self.test_crm_tags)
  103. self.assertEqual(lead.team_id, self.sales_team_1)
  104. self.assertEqual(lead.user_id, self.user_sales_leads)
  105. # iap
  106. self.assertEqual(lead.reveal_id, '123_ClearbitID_%s' % base_name, 'Ensure reveal_id is set to clearbit ID')
  107. # clearbit information
  108. self.assertFalse(lead.contact_name)
  109. self.assertEqual(lead.city, 'Mönchengladbach')
  110. self.assertEqual(lead.country_id, country_de)
  111. self.assertEqual(lead.email_from, 'info@%s.example.com' % base_name)
  112. self.assertFalse(lead.function)
  113. self.assertFalse(lead.partner_id)
  114. self.assertEqual(lead.partner_name, '%s GmbH legal_name' % base_name)
  115. self.assertEqual(lead.phone, '+4930499193937')
  116. self.assertEqual(lead.state_id, state_de)
  117. self.assertEqual(lead.street, 'Mennrather Str. 123456')
  118. self.assertEqual(lead.website, 'https://www.%s.de' % base_name)
  119. self.assertEqual(lead.zip, '41179')