test_res_partner_iap.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import psycopg2
  4. from odoo.addons.mail.tests.common import MailCommon
  5. from odoo.tools import mute_logger
  6. class TestResPartnerIap(MailCommon):
  7. @mute_logger("odoo.sql_db")
  8. def test_res_partner_iap_constraint(self):
  9. partner = self.partner_employee
  10. self.env["res.partner.iap"].search([("partner_id", "=", partner.id)]).unlink()
  11. self.env["res.partner.iap"].create({"partner_id": partner.id, "iap_enrich_info": "test info"})
  12. with self.assertRaises(psycopg2.IntegrityError, msg="Can create only one partner IAP per partner"):
  13. self.env["res.partner.iap"].create({"partner_id": partner.id, "iap_enrich_info": "test info"})
  14. def test_res_partner_iap_compute_iap_enrich_info(self):
  15. partner = self.partner_employee
  16. self.assertFalse(partner.iap_enrich_info)
  17. partner_iap = self.env["res.partner.iap"].create({"partner_id": partner.id, "iap_enrich_info": "test info"})
  18. partner.invalidate_recordset()
  19. self.assertEqual(partner.iap_enrich_info, "test info")
  20. partner_iap.unlink()
  21. partner.iap_enrich_info = "test info 2"
  22. partner_iap = self.env["res.partner.iap"].search([("partner_id", "=", partner.id)])
  23. self.assertTrue(partner_iap, "Should have create the <res.partner.iap>")
  24. self.assertEqual(partner_iap.iap_enrich_info, "test info 2")
  25. partner.iap_enrich_info = "test info 3"
  26. partner_iap.invalidate_recordset()
  27. new_partner_iap = self.env["res.partner.iap"].search([("partner_id", "=", partner.id)])
  28. self.assertEqual(new_partner_iap, partner_iap, "Should have write on the existing one")
  29. self.assertEqual(partner_iap.iap_enrich_info, "test info 3")
  30. def test_res_partner_iap_creation(self):
  31. partner = self.env['res.partner'].create({
  32. 'name': 'Test partner',
  33. 'iap_enrich_info': 'enrichment information',
  34. 'iap_search_domain': 'qsd@example.com',
  35. })
  36. partner.invalidate_recordset()
  37. self.assertEqual(partner.iap_enrich_info, 'enrichment information')
  38. self.assertEqual(partner.iap_search_domain, 'qsd@example.com')
  39. partner_iap = self.env['res.partner.iap'].search([('partner_id', '=', partner.id)])
  40. self.assertEqual(len(partner_iap), 1, 'Should create only one <res.partner.iap>')
  41. self.assertEqual(partner_iap.iap_enrich_info, 'enrichment information')
  42. self.assertEqual(partner_iap.iap_search_domain, 'qsd@example.com')
  43. def test_res_partner_iap_writing(self):
  44. partner = self.env['res.partner'].create({
  45. 'name': 'Test partner 2',
  46. })
  47. partner.write({
  48. 'iap_enrich_info': 'second information',
  49. 'iap_search_domain': 'xyz@example.com',
  50. })
  51. partner_iap = self.env['res.partner.iap'].search([('partner_id', '=', partner.id)])
  52. self.assertEqual(len(partner_iap), 1, 'Should create only one <res.partner.iap>')
  53. self.assertEqual(partner_iap.iap_enrich_info, 'second information')
  54. self.assertEqual(partner_iap.iap_search_domain, 'xyz@example.com')
  55. partner.iap_search_domain = "only write on domain"
  56. partner_iap.invalidate_recordset()
  57. self.assertEqual(partner_iap.iap_enrich_info, 'second information')
  58. self.assertEqual(partner_iap.iap_search_domain, 'only write on domain')