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.3 KiB

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