You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Daniel Reis
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase, at_install, post_install
  5. @at_install(False)
  6. @post_install(True)
  7. class NameSearchCase(TransactionCase):
  8. def setUp(self):
  9. super(NameSearchCase, self).setUp()
  10. phone_field = self.env.ref('base.field_res_partner_phone')
  11. model_partner = self.env.ref('base.model_res_partner')
  12. model_partner.name_search_ids = phone_field
  13. self.Partner = self.env['res.partner']
  14. self.partner1 = self.Partner.create(
  15. {'name': 'Luigi Verconti',
  16. 'customer': True,
  17. 'phone': '+351 555 777 333'})
  18. self.partner2 = self.Partner.create(
  19. {'name': 'Ken Shabby',
  20. 'customer': True,
  21. 'phone': '+351 555 333 777'})
  22. self.partner3 = self.Partner.create(
  23. {'name': 'Johann Gambolputty of Ulm',
  24. 'supplier': True,
  25. 'phone': '+351 777 333 555'})
  26. def test_RelevanceOrderedResults(self):
  27. """Return results ordered by relevance"""
  28. res = self.Partner.name_search('555 777')
  29. self.assertEqual(
  30. res[0][0], self.partner1.id,
  31. 'Match full string honoring spaces')
  32. self.assertEqual(
  33. res[1][0], self.partner2.id,
  34. 'Match words honoring order of appearance')
  35. self.assertEqual(
  36. res[2][0], self.partner3.id,
  37. 'Match all words, regardless of order of appearance')
  38. def test_NameSearchMustMatchAllWords(self):
  39. """Must Match All Words"""
  40. res = self.Partner.name_search('ulm 555 777')
  41. self.assertFalse(res)
  42. def test_MustHonorDomain(self):
  43. """Must also honor a provided Domain"""
  44. res = self.Partner.name_search('+351', args=[('supplier', '=', True)])
  45. gambulputty = self.partner3.id
  46. self.assertEqual(len(res), 1)
  47. self.assertEqual(res[0][0], gambulputty)