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.

58 lines
2.3 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. def tearDown(self):
  32. super(AttachmentTestCase, self).tearDown()
  33. def test_attachment(self):
  34. self.param.set_param('ir_attachment.location', 'lobject')
  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. oid = attach.with_context({'oid': True}).store_lobject
  41. self.assertTrue(oid)
  42. attach.write({'datas': base64.b64encode(b"\xff data")})
  43. self.assertTrue(oid != attach.with_context({'oid': True}).store_lobject)
  44. self.assertTrue(attach.export_data(['datas']))
  45. self.assertTrue(attach.export_data(['datas'], raw_data=True))
  46. attach.unlink()
  47. @unittest.skip("The test takes a long time and is therefore skipped by default.")
  48. def test_migration(self):
  49. self.param.set_param('ir_attachment.location', 'lobject')
  50. self.attachment.force_storage()