test_views.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.tests import TransactionCase
  4. class TestViews(TransactionCase):
  5. def setUp(self):
  6. super().setUp()
  7. View = self.env['ir.ui.view']
  8. self.first_view = View.create({
  9. 'name': 'Test View 1',
  10. 'type': 'qweb',
  11. 'arch': '<div>Hello World</div>',
  12. 'key': 'web_editor.test_first_view',
  13. })
  14. self.second_view = View.create({
  15. 'name': 'Test View 2',
  16. 'type': 'qweb',
  17. 'arch': '<div><t t-call="web_editor.test_first_view"/></div>',
  18. 'key': 'web_editor.test_second_view',
  19. })
  20. def test_infinite_inherit_loop(self):
  21. # Creates an infinite loop: A t-call B and A inherit from B
  22. View = self.env['ir.ui.view']
  23. self.second_view.write({
  24. 'inherit_id': self.first_view.id,
  25. })
  26. # Test for RecursionError: maximum recursion depth exceeded in this function
  27. View._views_get(self.first_view)
  28. def test_oe_structure_as_inherited_view(self):
  29. View = self.env['ir.ui.view']
  30. base = View.create({
  31. 'name': 'Test View oe_structure',
  32. 'type': 'qweb',
  33. 'arch': """<xpath expr='//t[@t-call="web_editor.test_first_view"]' position='after'>
  34. <div class="oe_structure" id='oe_structure_test_view_oe_structure'/>
  35. </xpath>""",
  36. 'key': 'web_editor.oe_structure_view',
  37. 'inherit_id': self.second_view.id
  38. })
  39. # check view mode
  40. self.assertEqual(base.mode, 'extension')
  41. # update content of the oe_structure
  42. value = '''<div class="oe_structure" id="oe_structure_test_view_oe_structure" data-oe-id="%s"
  43. data-oe-xpath="/div" data-oe-model="ir.ui.view" data-oe-field="arch">
  44. <p>Hello World!</p>
  45. </div>''' % base.id
  46. base.save(value=value, xpath='/xpath/div')
  47. self.assertEqual(len(base.inherit_children_ids), 1)
  48. self.assertEqual(base.inherit_children_ids.mode, 'extension')
  49. self.assertIn(
  50. '<p>Hello World!</p>',
  51. base.inherit_children_ids.get_combined_arch(),
  52. )
  53. def test_find_available_name(self):
  54. View = self.env['ir.ui.view']
  55. used_names = ['Unrelated name']
  56. initial_name = "Test name"
  57. name = View._find_available_name(initial_name, used_names)
  58. self.assertEqual(initial_name, name)
  59. used_names.append(name)
  60. name = View._find_available_name(initial_name, used_names)
  61. self.assertEqual('Test name (2)', name)
  62. used_names.append(name)
  63. name = View._find_available_name(initial_name, used_names)
  64. self.assertEqual('Test name (3)', name)