Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

118 linhas
4.5KB

  1. # Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import os
  5. import re
  6. from filecmp import dircmp
  7. import pathlib
  8. import shutil
  9. import unittest
  10. from odoo_module_migrate.__main__ import main
  11. from odoo_module_migrate.tools import _read_content
  12. class TestMigration(unittest.TestCase):
  13. _template_path = pathlib.Path("./tests/data_template").resolve()
  14. _working_path = pathlib.Path("./tests/data_tmp").resolve()
  15. _expected_path = pathlib.Path("./tests/data_result").resolve()
  16. def _migrate_module(
  17. self, module_name, result_name, init_version_name, target_version_name
  18. ):
  19. shutil.rmtree(self._working_path, ignore_errors=True)
  20. shutil.copytree(self._template_path, self._working_path)
  21. main([
  22. "--directory", str(self._working_path),
  23. "--init-version-name", init_version_name,
  24. "--target-version-name", target_version_name,
  25. "--modules", module_name,
  26. "--log-path", str(self._working_path / "test_log.log"),
  27. "--no-commit",
  28. ])
  29. def _get_comparison(self, module_name, result_name):
  30. comparison = dircmp(
  31. str(self._expected_path / result_name),
  32. str(self._working_path / module_name))
  33. return comparison
  34. def _get_diff_files(self, comparison, folder):
  35. res = [os.path.join(folder, x) for x in comparison.diff_files]
  36. for subfolder, subcomparison in comparison.subdirs.items():
  37. res += self._get_diff_files(
  38. subcomparison, os.path.join(folder, subfolder))
  39. return res
  40. def test_migration_080_130(self):
  41. self._migrate_module("module_080", "module_080_130", "8.0", "13.0")
  42. comparison = self._get_comparison("module_080", "module_080_130")
  43. diff_files = self._get_diff_files(comparison, "./")
  44. self.assertEqual(
  45. len(diff_files), 0,
  46. "Differences found in the following files\n- %s" % (
  47. "\n- ".join(diff_files)))
  48. log_content = _read_content(str(self._working_path / "test_log.log"))
  49. required_logs = [
  50. ("ERROR", "web_kanban_sparkline.*should remove the dependency"),
  51. ("WARNING", "Replaced.*account_analytic_analysis.*contract'"),
  52. ("ERROR", "deprecated decorator.*@api.cr"),
  53. ("ERROR", "ir.values.*removed"),
  54. ("ERROR", "removed module.*account_anglo_saxon"),
  55. ]
  56. for required_log in required_logs:
  57. level, message = required_log
  58. pattern = "{0}.*{1}".format(level, message)
  59. self.assertNotEqual(
  60. len(re.findall(pattern, log_content)),
  61. 0,
  62. "%s not found in the log" % pattern)
  63. def test_migration_120_130(self):
  64. self._migrate_module("module_120", "module_120_130", "12.0", "13.0")
  65. comparison = self._get_comparison("module_120", "module_120_130")
  66. diff_files = self._get_diff_files(comparison, "./")
  67. log_content = _read_content(str(self._working_path / "test_log.log"))
  68. self.assertEqual(
  69. len(diff_files), 0,
  70. "Differences found in the following files\n- %s" % (
  71. "\n- ".join(diff_files)))
  72. required_logs = [
  73. (
  74. "WARNING",
  75. "[13].*change.*env\\.user\\.company_id.*to.*\\.env\\.company",
  76. ),
  77. ]
  78. for required_log in required_logs:
  79. level, message = required_log
  80. pattern = "{0}.*{1}".format(level, message)
  81. self.assertNotEqual(
  82. len(re.findall(pattern, log_content)),
  83. 0,
  84. "%s not found in the log" % pattern)
  85. def test_migration_130_140(self):
  86. self._migrate_module("module_130", "module_130_140", "13.0", "14.0")
  87. comparison = self._get_comparison("module_130", "module_130_140")
  88. diff_files = self._get_diff_files(comparison, "./")
  89. self.assertEqual(
  90. len(diff_files), 0,
  91. "Differences found in the following files\n- %s" % (
  92. "\n- ".join(diff_files)))
  93. def test_migration_150_160(self):
  94. self._migrate_module("module_150", "module_150_160", "15.0", "16.0")
  95. comparison = self._get_comparison("module_150", "module_150_160")
  96. diff_files = self._get_diff_files(comparison, "./")
  97. self.assertEqual(
  98. len(diff_files), 0,
  99. "Differences found in the following files\n- %s" % (
  100. "\n- ".join(diff_files)))
上海开阖软件有限公司 沪ICP备12045867号-1