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.

72 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 os
  20. import time
  21. import hmac
  22. import base64
  23. import hashlib
  24. import logging
  25. from odoo.http import request
  26. from odoo.addons.muk_utils.tests import common
  27. _path = os.path.dirname(os.path.dirname(__file__))
  28. _logger = logging.getLogger(__name__)
  29. class DownloadTestCase(common.HttpCase):
  30. def setUp(self):
  31. super(DownloadTestCase, self).setUp()
  32. self.attachment = self.env['ir.attachment'].sudo()
  33. self.param = self.env['ir.config_parameter'].sudo()
  34. self.param.set_param('ir_attachment.location', 'lobject')
  35. def tearDown(self):
  36. super(DownloadTestCase, self).tearDown()
  37. def test_attachment_download(self):
  38. self.authenticate('admin', 'admin')
  39. attach_01 = self.attachment.create({
  40. 'name': "Test_01",
  41. 'datas': base64.b64encode(b"\xff data")
  42. })
  43. attach_02 = self.attachment.create({
  44. 'name': "Test_02",
  45. })
  46. self.assertTrue(attach_01.datas)
  47. self.assertFalse(attach_02.datas)
  48. data = {
  49. 'model': 'ir.attachment',
  50. 'field': 'store_lobject',
  51. 'filename_field': 'datas_fname',
  52. }
  53. data.update({
  54. 'id': attach_01.id,
  55. })
  56. self.assertTrue(self.url_open('/web/lobject', data=data, csrf=True))
  57. data.update({
  58. 'id': attach_02.id,
  59. })
  60. self.assertTrue(self.url_open('/web/lobject', data=data, csrf=True))