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.

44 lines
1.6 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. 'phone': '+351 555 777 333'})
  17. self.partner2 = self.Partner.create(
  18. {'name': 'Ken Shabby',
  19. 'phone': '+351 555 333 777'})
  20. self.partner3 = self.Partner.create(
  21. {'name': 'Johann Gambolputty of Ulm',
  22. 'phone': '+351 777 333 555'})
  23. def test_RelevanceOrderedResults(self):
  24. """Return results ordered by relevance"""
  25. res = self.Partner.name_search('555 777')
  26. self.assertEqual(
  27. res[0][0], self.partner1.id,
  28. 'Match full string honoring spaces')
  29. self.assertEqual(
  30. res[1][0], self.partner2.id,
  31. 'Match words honoring order of appearance')
  32. self.assertEqual(
  33. res[2][0], self.partner3.id,
  34. 'Match all words, regardless of order of appearance')
  35. def test_NameSearchMustMatchAllWords(self):
  36. """Must Match All Words"""
  37. res = self.Partner.name_search('ulm 555 777')
  38. self.assertFalse(res)