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.

71 lines
2.7 KiB

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