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.

73 lines
2.8 KiB

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