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.

69 lines
2.6 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Utils
  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. import logging
  22. from odoo.osv import expression
  23. from odoo.tests import common
  24. _logger = logging.getLogger(__name__)
  25. class MigrationTestCase(common.TransactionCase):
  26. def setUp(self):
  27. super(MigrationTestCase, self).setUp()
  28. self.model = self.env["ir.attachment"]
  29. self.params = self.env["ir.config_parameter"].sudo()
  30. self.location = self.params.get_param("ir_attachment.location")
  31. if self.location == "file":
  32. self.params.set_param("ir_attachment.location", "db")
  33. else:
  34. self.params.set_param("ir_attachment.location", "file")
  35. def tearDown(self):
  36. self.params.set_param("ir_attachment.location", self.location)
  37. super(MigrationTestCase, self).tearDown()
  38. def test_storage_domain(self):
  39. self.assertEqual(
  40. self.model._get_storage_domain("db"), [("db_datas", "=", False)]
  41. )
  42. self.assertEqual(
  43. self.model._get_storage_domain("file"), [("store_fname", "=", False)]
  44. )
  45. def test_force_storage_domain(self):
  46. force_storage_domain = expression.AND(
  47. [
  48. self.model._get_storage_domain("db"),
  49. [
  50. "&",
  51. "|",
  52. ("res_field", "=", False),
  53. ("res_field", "!=", False),
  54. ("type", "=", "binary"),
  55. ],
  56. ]
  57. )
  58. self.assertFalse(expression.is_false(self.model, force_storage_domain))
  59. def test_migration(self):
  60. self.model.search([("type", "=", "binary")], limit=25).migrate()