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.

161 lines
6.6 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Authors: Cédric Pigeon
  5. # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published
  9. # by the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import logging
  22. import base64
  23. from lxml import etree as ET
  24. from anybox.testing.openerp import SharedSetupTransactionCase
  25. _logger = logging.getLogger(__name__)
  26. class test_export_help_wizard(object):
  27. _data_files = ('data/help_test_data.xml',)
  28. _module_ns = 'help_online'
  29. def createPage(self, pageName, imgXmlId=False):
  30. imgId = False
  31. if imgXmlId:
  32. imgId = self.ref('%s.%s' % (self._module_ns, imgXmlId))
  33. rootNode = ET.Element('t')
  34. rootNode.attrib['name'] = pageName
  35. rootNode.attrib['t-name'] = "website.%s" % pageName
  36. tNode = ET.SubElement(rootNode,
  37. 't',
  38. attrib={'t-call': 'website.layout'})
  39. structDivNode = ET.SubElement(tNode,
  40. 'div',
  41. attrib={'class': 'oe_structure oe_empty',
  42. 'id': 'wrap'})
  43. sectionNode = ET.SubElement(structDivNode,
  44. 'section',
  45. attrib={'class': 'mt16 mb16'})
  46. containerNode = ET.SubElement(sectionNode,
  47. 'div',
  48. attrib={'class': 'container'})
  49. rowNode = ET.SubElement(containerNode,
  50. 'div',
  51. attrib={'class': 'row'})
  52. bodyDivNode = ET.SubElement(rowNode,
  53. 'div',
  54. attrib={'class': 'col-md-12 '
  55. 'text-center mt16 mb32'})
  56. style = "font-family: 'Helvetica Neue', Helvetica,"\
  57. " Arial, sans-serif; color: rgb(51, 51, 51);"\
  58. " text-align: left;"
  59. h2Node = ET.SubElement(bodyDivNode,
  60. 'h2',
  61. attrib={'style': style})
  62. h2Node.text = "Test Sample Title"
  63. if imgId:
  64. imgDivNode = ET.SubElement(bodyDivNode,
  65. 'div',
  66. attrib={'style': 'text-align: left;'})
  67. src = "/website/image?field=datas&"\
  68. "model=ir.attachment&id=%s" % str(imgId)
  69. ET.SubElement(imgDivNode,
  70. 'img',
  71. attrib={'class': 'img-thumbnail',
  72. 'src': src})
  73. imgDivNode = ET.SubElement(bodyDivNode,
  74. 'div',
  75. attrib={'style': 'text-align: left;'})
  76. src = "/website/image/ir.attachment/%s_ccc838d/datas" % str(imgId)
  77. ET.SubElement(imgDivNode,
  78. 'img',
  79. attrib={'class': 'img-thumbnail',
  80. 'src': src})
  81. arch = ET.tostring(rootNode, encoding='utf-8', xml_declaration=False)
  82. vals = {
  83. 'name': pageName,
  84. 'type': 'qweb',
  85. 'arch': arch,
  86. 'page': True,
  87. }
  88. view_id = self.env['ir.ui.view'].create(vals)
  89. return view_id.id
  90. def setUp(self):
  91. super(test_export_help_wizard, self).setUp()
  92. self.pageName = False
  93. self.imgXmlId = False
  94. self.pageTemplate = False
  95. def test_export_help(self):
  96. """
  97. Export help data
  98. """
  99. self.createPage(pageName=self.pageName, imgXmlId=self.imgXmlId)
  100. wizardPool = self.env['export.help.wizard']
  101. wizard = wizardPool.create({})
  102. wizard.export_help()
  103. xmlData = base64.decodestring(wizard.data)
  104. parser = ET.XMLParser(remove_blank_text=True)
  105. rootXml = ET.XML(xmlData, parser=parser)
  106. xPath = ".//template[@id='website.%s']" % self.pageName
  107. templateNodeList = rootXml.findall(xPath)
  108. self.assertEqual(len(templateNodeList), 1)
  109. self.assertNotIn("website.", templateNodeList[0].attrib['name'])
  110. if self.imgXmlId:
  111. xPath = ".//record[@id='%s']" % self.imgXmlId
  112. imgNodeList = rootXml.findall(xPath)
  113. self.assertEqual(len(imgNodeList), 2)
  114. for imgElem in templateNodeList[0].iter('img'):
  115. imgSrc = imgElem.get('src')
  116. if '/ir.attachment/' in imgSrc:
  117. self.assertIn("/ir.attachment/%s|"
  118. % self.imgXmlId, imgSrc)
  119. else:
  120. self.assertIn("id=%s" % self.imgXmlId, imgSrc)
  121. if self.pageTemplate:
  122. xPath = ".//template[@id='website.%s_snippet']" % self.pageName
  123. templateNodeList = rootXml.findall(xPath)
  124. self.assertEqual(len(templateNodeList), 1)
  125. self.assertNotIn("website.", templateNodeList[0].attrib['name'])
  126. class test_export_help_with_image(test_export_help_wizard,
  127. SharedSetupTransactionCase):
  128. def setUp(self):
  129. super(test_export_help_with_image, self).setUp()
  130. parameter_model = self.env['ir.config_parameter']
  131. page_prefix = parameter_model.get_param('help_online_page_prefix')
  132. self.pageName = '%stest-page' % page_prefix
  133. self.imgXmlId = 'test_img_1'
  134. class test_export_help_template(test_export_help_wizard,
  135. SharedSetupTransactionCase):
  136. def setUp(self):
  137. super(test_export_help_template, self).setUp()
  138. parameter_model = self.env['ir.config_parameter']
  139. param = 'help_online_template_prefix'
  140. template_prefix = parameter_model.get_param(param)
  141. self.pageName = '%stest-template' % template_prefix
  142. self.pageTemplate = True