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

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Large Objects Attachment
  6. # (see https://mukit.at).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###################################################################################
  22. import base64
  23. import logging
  24. import os
  25. from odoo.addons.muk_utils.tests import common
  26. _path = os.path.dirname(os.path.dirname(__file__))
  27. _logger = logging.getLogger(__name__)
  28. class DownloadTestCase(common.HttpCase):
  29. def setUp(self):
  30. super(DownloadTestCase, self).setUp()
  31. self.attachment = self.env["ir.attachment"].sudo()
  32. self.params = self.env["ir.config_parameter"].sudo()
  33. self.location = self.params.get_param("ir_attachment.location")
  34. self.params.set_param("ir_attachment.location", "lobject")
  35. def tearDown(self):
  36. self.params.set_param("ir_attachment.location", self.location)
  37. super(DownloadTestCase, self).tearDown()
  38. def test_attachment_download(self):
  39. self.authenticate("admin", "admin")
  40. attach_01 = self.attachment.create(
  41. {"name": "Test_01", "datas": base64.b64encode(b"\xff data")}
  42. )
  43. attach_02 = self.attachment.create({"name": "Test_02"})
  44. self.assertTrue(attach_01.datas)
  45. self.assertFalse(attach_02.datas)
  46. data = {
  47. "model": "ir.attachment",
  48. "field": "store_lobject",
  49. "filename_field": "datas_fname",
  50. }
  51. data.update({"id": attach_01.id})
  52. self.assertTrue(self.url_open("/binary/content", data=data, csrf=True))
  53. data.update({"id": attach_02.id})
  54. self.assertTrue(self.url_open("/binary/content", data=data, csrf=True))