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.

65 lines
2.7 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Large Objects Attachment
  6. # (see https://mukit.at).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###################################################################################
  22. import base64
  23. import logging
  24. import unittest
  25. from odoo.tests import common
  26. _logger = logging.getLogger(__name__)
  27. class AttachmentTestCase(common.HttpCase):
  28. def setUp(self):
  29. super(AttachmentTestCase, self).setUp()
  30. self.attachment = self.env["ir.attachment"].sudo()
  31. self.params = self.env["ir.config_parameter"].sudo()
  32. self.location = self.params.get_param("ir_attachment.location")
  33. self.params.set_param("ir_attachment.location", "lobject")
  34. def tearDown(self):
  35. self.params.set_param("ir_attachment.location", self.location)
  36. super(AttachmentTestCase, self).tearDown()
  37. def test_attachment(self):
  38. attach = self.attachment.create(
  39. {"name": "Test", "datas": base64.b64encode(b"\xff data")}
  40. )
  41. self.assertTrue(attach.datas)
  42. self.assertTrue(attach.store_lobject)
  43. self.assertTrue(attach.with_context({"bin_size": True}).datas)
  44. self.assertTrue(attach.with_context({"bin_size": True}).store_lobject)
  45. self.assertTrue(attach.with_context({"human_size": True}).store_lobject)
  46. self.assertTrue(attach.with_context({"base64": True}).store_lobject)
  47. self.assertTrue(attach.with_context({"stream": True}).store_lobject)
  48. oid = attach.with_context({"oid": True}).store_lobject
  49. self.assertTrue(oid)
  50. attach.write({"datas": base64.b64encode(b"\xff data")})
  51. self.assertTrue(oid != attach.with_context({"oid": True}).store_lobject)
  52. self.assertTrue(attach.export_data(["datas"]))
  53. self.assertTrue(attach.export_data(["datas"], raw_data=True))
  54. attach.unlink()
  55. @unittest.skip("The test takes a long time and is therefore skipped by default.")
  56. def test_migration(self):
  57. self.attachment.force_storage()