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.

42 lines
1.3 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. import mock
  5. from .common import SyncCommon
  6. from odoo.tools import mute_logger
  7. def raising_side_effect(*args, **kwargs):
  8. raise Exception("Boom")
  9. class TestExport(SyncCommon):
  10. def setUp(self):
  11. super().setUp()
  12. self.task = self.env.ref("attachment_synchronize.export_to_filestore")
  13. self.attachment = self.env["attachment.queue"].create(
  14. {
  15. "name": "foo.txt",
  16. "datas_fname": "foo.txt",
  17. "task_id": self.task.id,
  18. "file_type": "export",
  19. "datas": self.filedata,
  20. }
  21. )
  22. def test_export(self):
  23. self.attachment.run()
  24. result = self.backend._list("test_export")
  25. self.assertEqual(result, ["foo.txt"])
  26. @mute_logger("odoo.addons.attachment_queue.models.attachment_queue")
  27. def test_failing_export(self):
  28. with mock.patch.object(
  29. type(self.backend),
  30. "_add_b64_data",
  31. side_effect=raising_side_effect,
  32. ):
  33. self.attachment.run()
  34. self.assertEqual(self.attachment.state, "failed")
  35. self.assertEqual(self.attachment.state_message, "Boom")