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.

68 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from os import path
  5. from openerp.tests.common import TransactionCase
  6. PATH = path.join(path.dirname(__file__), "import_data", "%s.csv")
  7. OPTIONS = {
  8. "headers": True,
  9. "quoting": '"',
  10. "separator": ",",
  11. }
  12. class ImportCase(TransactionCase):
  13. def _base_import_record(self, res_model, file_name):
  14. """Create and return a ``base_import.import`` record."""
  15. with open(PATH % file_name) as demo_file:
  16. return self.env["base_import.import"].create({
  17. "res_model": res_model,
  18. "file": demo_file.read(),
  19. "file_name": "%s.csv" % file_name,
  20. "file_type": "csv",
  21. })
  22. def test_res_partner_vat(self):
  23. """Change name based on VAT."""
  24. agrolait = self.env.ref("base.res_partner_2")
  25. agrolait.vat = "BE0477472701"
  26. record = self._base_import_record("res.partner", "res_partner_vat")
  27. record.do(["name", "vat", "is_company"], OPTIONS)
  28. agrolait.env.invalidate_all()
  29. self.assertEqual(agrolait.name, "Agrolait Changed")
  30. def test_res_partner_parent_name_is_company(self):
  31. """Change email based on parent_id, name and is_company."""
  32. record = self._base_import_record(
  33. "res.partner", "res_partner_parent_name_is_company")
  34. record.do(["name", "is_company", "parent_id/id", "email"], OPTIONS)
  35. self.assertEqual(
  36. self.env.ref("base.res_partner_address_4").email,
  37. "changed@agrolait.example.com")
  38. def test_res_partner_email(self):
  39. """Change name based on email."""
  40. record = self._base_import_record("res.partner", "res_partner_email")
  41. record.do(["email", "name"], OPTIONS)
  42. self.assertEqual(
  43. self.env.ref("base.res_partner_address_4").name,
  44. "Michel Fletcher Changed")
  45. def test_res_partner_name(self):
  46. """Change function based on name."""
  47. record = self._base_import_record("res.partner", "res_partner_name")
  48. record.do(["function", "name"], OPTIONS)
  49. self.assertEqual(
  50. self.env.ref("base.res_partner_address_4").function,
  51. "Function Changed")
  52. def test_res_users_login(self):
  53. """Change name based on login."""
  54. record = self._base_import_record("res.users", "res_users_login")
  55. record.do(["login", "name"], OPTIONS)
  56. self.assertEqual(
  57. self.env.ref("base.user_demo").name,
  58. "Demo User Changed")