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.

87 lines
3.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. # Copyright 2020 Akretion (http://www.akretion.com).
  2. # @author Sébastien BEAU <sebastien.beau@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from .common import SyncCommon
  5. class TestImport(SyncCommon):
  6. @property
  7. def archived_files(self):
  8. return self.backend._list(self.directory_archived)
  9. @property
  10. def input_files(self):
  11. return self.backend._list(self.directory_input)
  12. def _check_attachment_created(self, count=1):
  13. attachment = self.env["attachment.queue"].search(
  14. [("name", "=", "bar.txt")]
  15. )
  16. self.assertEqual(len(attachment), count)
  17. def test_import_with_rename(self):
  18. self.task.write({"after_import": "rename", "new_name": "foo.txt"})
  19. self.task.run_import()
  20. self._check_attachment_created()
  21. self.assertEqual(self.input_files, ["foo.txt"])
  22. self.assertEqual(self.archived_files, [])
  23. def test_import_with_move(self):
  24. self.task.write(
  25. {"after_import": "move", "move_path": self.directory_archived}
  26. )
  27. self.task.run_import()
  28. self._check_attachment_created()
  29. self.assertEqual(self.input_files, [])
  30. self.assertEqual(self.archived_files, ["bar.txt"])
  31. def test_import_with_move_and_rename(self):
  32. self.task.write(
  33. {
  34. "after_import": "move_rename",
  35. "new_name": "foo.txt",
  36. "move_path": self.directory_archived,
  37. }
  38. )
  39. self.task.run_import()
  40. self._check_attachment_created()
  41. self.assertEqual(self.input_files, [])
  42. self.assertEqual(self.archived_files, ["foo.txt"])
  43. def test_import_with_delete(self):
  44. self.task.write({"after_import": "delete"})
  45. self.task.run_import()
  46. self._check_attachment_created()
  47. self.assertEqual(self.input_files, [])
  48. self.assertEqual(self.archived_files, [])
  49. def test_import_twice(self):
  50. self.task.write({"after_import": "delete"})
  51. self.task.run_import()
  52. self._check_attachment_created(count=1)
  53. self._create_test_file()
  54. self.task.run_import()
  55. self._check_attachment_created(count=2)
  56. def test_import_twice_no_duplicate(self):
  57. self.task.write(
  58. {"after_import": "delete", "check_duplicated_files": True}
  59. )
  60. self.task.run_import()
  61. self._check_attachment_created(count=1)
  62. self._create_test_file()
  63. self.task.run_import()
  64. self._check_attachment_created(count=1)
  65. def test_running_cron(self):
  66. self.task.write({"after_import": "delete"})
  67. self.env["attachment.synchronize.task"].run_task_import_scheduler()
  68. self._check_attachment_created(count=1)
  69. def test_running_cron_disable_task(self):
  70. self.task.write({"after_import": "delete", "enabled": False})
  71. self.env["attachment.synchronize.task"].run_task_import_scheduler()
  72. self._check_attachment_created(count=0)