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.

101 lines
4.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import os
  5. import sys
  6. from lxml import etree as ET
  7. from odoo.tools.convert import convert_xml_import
  8. class TestWizardCommon(object):
  9. _data_files = ('data/help_test_data.xml',)
  10. _module_ns = 'help_online'
  11. def createPage(self, pageName, imgXmlId=False):
  12. imgId = False
  13. if imgXmlId:
  14. imgId = self.ref(imgXmlId)
  15. rootNode = ET.Element('t')
  16. rootNode.attrib['name'] = pageName
  17. rootNode.attrib['t-name'] = "website.%s" % pageName
  18. tNode = ET.SubElement(rootNode,
  19. 't',
  20. attrib={'t-call': 'website.layout'})
  21. structDivNode = ET.SubElement(tNode,
  22. 'div',
  23. attrib={'class': 'oe_structure oe_empty',
  24. 'id': 'wrap'})
  25. sectionNode = ET.SubElement(structDivNode,
  26. 'section',
  27. attrib={'class': 'mt16 mb16'})
  28. containerNode = ET.SubElement(sectionNode,
  29. 'div',
  30. attrib={'class': 'container'})
  31. rowNode = ET.SubElement(containerNode,
  32. 'div',
  33. attrib={'class': 'row'})
  34. bodyDivNode = ET.SubElement(rowNode,
  35. 'div',
  36. attrib={'class': 'col-md-12 '
  37. 'text-center mt16 mb32'})
  38. style = "font-family: 'Helvetica Neue', Helvetica,"\
  39. " Arial, sans-serif; color: rgb(51, 51, 51);"\
  40. " text-align: left;"
  41. h2Node = ET.SubElement(bodyDivNode,
  42. 'h2',
  43. attrib={'style': style})
  44. h2Node.text = "Test Sample Title"
  45. if imgId:
  46. imgDivNode = ET.SubElement(bodyDivNode,
  47. 'div',
  48. attrib={'style': 'text-align: left;'})
  49. src = "/website/image?field=datas&"\
  50. "model=ir.attachment&id=%s" % str(imgId)
  51. ET.SubElement(imgDivNode,
  52. 'img',
  53. attrib={'class': 'img-thumbnail',
  54. 'src': src})
  55. imgDivNode = ET.SubElement(bodyDivNode,
  56. 'div',
  57. attrib={'style': 'text-align: left;'})
  58. src = "/website/image/ir.attachment/%s_ccc838d/datas" % str(imgId)
  59. ET.SubElement(imgDivNode,
  60. 'img',
  61. attrib={'class': 'img-thumbnail',
  62. 'src': src})
  63. imgDivNode = ET.SubElement(bodyDivNode,
  64. 'div',
  65. attrib={'style': 'text-align: left;'})
  66. src = "/web/image/%s" % str(imgId)
  67. ET.SubElement(imgDivNode,
  68. 'img',
  69. attrib={'class': 'img-thumbnail',
  70. 'src': src})
  71. arch = ET.tostring(rootNode, encoding='utf-8', xml_declaration=False)
  72. vals = {
  73. 'name': pageName,
  74. 'type': 'qweb',
  75. 'arch': arch,
  76. 'page': True,
  77. 'key': 'website.%s' % pageName
  78. }
  79. view_id = self.env['ir.ui.view'].create(vals)
  80. return view_id.id
  81. def setUp(self):
  82. super(TestWizardCommon, self).setUp()
  83. self.pageName = False
  84. self.imgXmlId = False
  85. self.pageTemplate = False
  86. # Loads the data file before
  87. module = sys.modules[self.__class__.__module__]
  88. base_path = os.path.dirname(module.__file__)
  89. for path in self._data_files:
  90. path = path.split('/')
  91. path.insert(0, base_path)
  92. path = os.path.join(*path)
  93. convert_xml_import(self.cr, self._module_ns, path)