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.

74 lines
2.8 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 odoo.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='__export__.%s']" % self.pageName
  23. templateNodeList = rootXml.findall(xPath)
  24. self.assertEqual(len(templateNodeList), 1)
  25. self.assertNotIn("website.", templateNodeList[0].attrib['name'])
  26. self.assertEqual(
  27. "website." + self.pageName, templateNodeList[0].attrib['key'])
  28. if self.imgXmlId:
  29. xPath = ".//record[@id='%s']" % self.imgXmlId
  30. imgNodeList = rootXml.findall(xPath)
  31. self.assertEqual(len(imgNodeList), 1,
  32. 'The same image should be exported only once')
  33. for imgElem in templateNodeList[0].iter('img'):
  34. imgSrc = imgElem.get('src')
  35. if '/ir.attachment/' in imgSrc:
  36. self.assertIn("/ir.attachment/%s|"
  37. % self.imgXmlId, imgSrc)
  38. else:
  39. self.assertIn("/web/image/%s" % self.imgXmlId, imgSrc)
  40. if self.pageTemplate:
  41. xPath = ".//template[@id='__export__.%s_snippet']" % self.pageName
  42. templateNodeList = rootXml.findall(xPath)
  43. self.assertEqual(len(templateNodeList), 1)
  44. self.assertNotIn("website.", templateNodeList[0].attrib['name'])
  45. class TestExportHelpWithImage(TestExportHelpWizard, common.TransactionCase):
  46. def setUp(self):
  47. super(TestExportHelpWithImage, self).setUp()
  48. parameter_model = self.env['ir.config_parameter']
  49. page_prefix = parameter_model.get_param('help_online_page_prefix')
  50. self.pageName = '%stest-page' % page_prefix
  51. self.imgXmlId = '%s.test_img_1' % self._module_ns
  52. class TestExportHelpTemplate(TestExportHelpWizard, common.TransactionCase):
  53. def setUp(self):
  54. super(TestExportHelpTemplate, self).setUp()
  55. parameter_model = self.env['ir.config_parameter']
  56. param = 'help_online_template_prefix'
  57. template_prefix = parameter_model.get_param(param)
  58. self.pageName = '%stest-template' % template_prefix
  59. self.pageTemplate = True