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.

72 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import base64
  5. from lxml import etree as ET
  6. import openerp.tests.common as common
  7. from .common import TestWizardCommon
  8. class TestExportHelpWizard(TestWizardCommon):
  9. pageName = None
  10. imgXmlId = None
  11. def test_export_help(self):
  12. """
  13. Export help data
  14. """
  15. self.createPage(pageName=self.pageName, imgXmlId=self.imgXmlId)
  16. wizardPool = self.env['export.help.wizard']
  17. wizard = wizardPool.create({})
  18. wizard.export_help()
  19. xmlData = base64.decodestring(wizard.data)
  20. parser = ET.XMLParser(remove_blank_text=True)
  21. rootXml = ET.XML(xmlData, parser=parser)
  22. xPath = ".//template[@id='website.%s']" % self.pageName
  23. templateNodeList = rootXml.findall(xPath)
  24. self.assertEqual(len(templateNodeList), 1)
  25. self.assertNotIn("website.", templateNodeList[0].attrib['name'])
  26. if self.imgXmlId:
  27. xPath = ".//record[@id='%s']" % self.imgXmlId
  28. imgNodeList = rootXml.findall(xPath)
  29. self.assertEqual(len(imgNodeList), 1,
  30. 'The same image should be exported only once')
  31. for imgElem in templateNodeList[0].iter('img'):
  32. imgSrc = imgElem.get('src')
  33. if '/ir.attachment/' in imgSrc:
  34. self.assertIn("/ir.attachment/%s|"
  35. % self.imgXmlId, imgSrc)
  36. else:
  37. self.assertIn("/web/image/%s" % self.imgXmlId, imgSrc)
  38. if self.pageTemplate:
  39. xPath = ".//template[@id='website.%s_snippet']" % self.pageName
  40. templateNodeList = rootXml.findall(xPath)
  41. self.assertEqual(len(templateNodeList), 1)
  42. self.assertNotIn("website.", templateNodeList[0].attrib['name'])
  43. class TestExportHelpWithImage(TestExportHelpWizard, common.TransactionCase):
  44. def setUp(self):
  45. super(TestExportHelpWithImage, self).setUp()
  46. parameter_model = self.env['ir.config_parameter']
  47. page_prefix = parameter_model.get_param('help_online_page_prefix')
  48. self.pageName = '%stest-page' % page_prefix
  49. self.imgXmlId = '%s.test_img_1' % self._module_ns
  50. class TestExportHelpTemplate(TestExportHelpWizard, common.TransactionCase):
  51. def setUp(self):
  52. super(TestExportHelpTemplate, self).setUp()
  53. parameter_model = self.env['ir.config_parameter']
  54. param = 'help_online_template_prefix'
  55. template_prefix = parameter_model.get_param(param)
  56. self.pageName = '%stest-template' % template_prefix
  57. self.pageTemplate = True