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.

60 lines
2.4 KiB

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