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.

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