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.

169 lines
7.1 KiB

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