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.

83 lines
2.9 KiB

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([("name", "=", "bar.txt")])
  14. self.assertEqual(len(attachment), count)
  15. def test_import_with_rename(self):
  16. self.task.write({"after_import": "rename", "new_name": "foo.txt"})
  17. self.task.run_import()
  18. self._check_attachment_created()
  19. self.assertEqual(self.input_files, ["foo.txt"])
  20. self.assertEqual(self.archived_files, [])
  21. def test_import_with_move(self):
  22. self.task.write({"after_import": "move", "move_path": self.directory_archived})
  23. self.task.run_import()
  24. self._check_attachment_created()
  25. self.assertEqual(self.input_files, [])
  26. self.assertEqual(self.archived_files, ["bar.txt"])
  27. def test_import_with_move_and_rename(self):
  28. self.task.write(
  29. {
  30. "after_import": "move_rename",
  31. "new_name": "foo.txt",
  32. "move_path": self.directory_archived,
  33. }
  34. )
  35. self.task.run_import()
  36. self._check_attachment_created()
  37. self.assertEqual(self.input_files, [])
  38. self.assertEqual(self.archived_files, ["foo.txt"])
  39. def test_import_with_delete(self):
  40. self.task.write({"after_import": "delete"})
  41. self.task.run_import()
  42. self._check_attachment_created()
  43. self.assertEqual(self.input_files, [])
  44. self.assertEqual(self.archived_files, [])
  45. def test_import_twice(self):
  46. self.task.write({"after_import": "delete"})
  47. self.task.run_import()
  48. self._check_attachment_created(count=1)
  49. self._create_test_file()
  50. self.task.run_import()
  51. self._check_attachment_created(count=2)
  52. def test_import_twice_no_duplicate(self):
  53. self.task.write(
  54. {"after_import": "delete", "avoid_duplicated_files": True}
  55. )
  56. self.task.run_import()
  57. self._check_attachment_created(count=1)
  58. self._create_test_file()
  59. self.task.run_import()
  60. self._check_attachment_created(count=1)
  61. def test_running_cron(self):
  62. self.task.write({"after_import": "delete"})
  63. self.env["attachment.synchronize.task"].run_task_import_scheduler()
  64. self._check_attachment_created(count=1)
  65. def test_running_cron_disable_task(self):
  66. self.task.write({"after_import": "delete", "enabled": False})
  67. self.env["attachment.synchronize.task"].run_task_import_scheduler()
  68. self._check_attachment_created(count=0)