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.

61 lines
2.6 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. def setUp(self):
  26. super(AttachmentTestCase, self).setUp()
  27. self.attachment = self.env['ir.attachment'].sudo()
  28. self.params = self.env['ir.config_parameter'].sudo()
  29. self.location = self.params.get_param('ir_attachment.location')
  30. self.params.set_param('ir_attachment.location', 'lobject')
  31. def tearDown(self):
  32. self.params.set_param('ir_attachment.location', self.location)
  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.store_lobject)
  40. self.assertTrue(attach.with_context({'bin_size': True}).datas)
  41. self.assertTrue(attach.with_context({'bin_size': True}).store_lobject)
  42. self.assertTrue(attach.with_context({'human_size': True}).store_lobject)
  43. self.assertTrue(attach.with_context({'base64': True}).store_lobject)
  44. self.assertTrue(attach.with_context({'stream': True}).store_lobject)
  45. oid = attach.with_context({'oid': True}).store_lobject
  46. self.assertTrue(oid)
  47. attach.write({'datas': base64.b64encode(b"\xff data")})
  48. self.assertTrue(oid != attach.with_context({'oid': True}).store_lobject)
  49. self.assertTrue(attach.export_data(['datas']))
  50. self.assertTrue(attach.export_data(['datas'], raw_data=True))
  51. attach.unlink()
  52. @unittest.skip("The test takes a long time and is therefore skipped by default.")
  53. def test_migration(self):
  54. self.attachment.force_storage()