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.

74 lines
2.5 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.params = self.env['ir.config_parameter'].sudo()
  34. self.location = self.params.get_param('ir_attachment.location')
  35. self.params.set_param('ir_attachment.location', 'lobject')
  36. def tearDown(self):
  37. self.params.set_param('ir_attachment.location', self.location)
  38. super(DownloadTestCase, self).tearDown()
  39. def test_attachment_download(self):
  40. self.authenticate('admin', 'admin')
  41. attach_01 = self.attachment.create({
  42. 'name': "Test_01",
  43. 'datas': base64.b64encode(b"\xff data")
  44. })
  45. attach_02 = self.attachment.create({
  46. 'name': "Test_02",
  47. })
  48. self.assertTrue(attach_01.datas)
  49. self.assertFalse(attach_02.datas)
  50. data = {
  51. 'model': 'ir.attachment',
  52. 'field': 'store_lobject',
  53. 'filename_field': 'datas_fname',
  54. }
  55. data.update({
  56. 'id': attach_01.id,
  57. })
  58. self.assertTrue(self.url_open('/web/lobject', data=data, csrf=True))
  59. data.update({
  60. 'id': attach_02.id,
  61. })
  62. self.assertTrue(self.url_open('/web/lobject', data=data, csrf=True))