Example #1
0
 def setUp(self):
     self.portal = self.layer['portal']
     self.value = XMLTextValue(
         raw='<html><body>test</body></html>',
         mimeType='text/xml',
         outputMimeType='text/html',
         encoding='utf-8'
     )
Example #2
0
    def eip_request(self):
        action = self.request.get('action',None)
        if not action:
            raise 'Bad Request', 'Action not specified.'

        xpath = self.request.get('xpath',None)
        if xpath:
            del self.request.form['xpath']
        position = self.request.get('position',None)
        content = self.request.get('content',None)

        bodyfield = self.context.body

        if action=='add' and xpath and position and content:
            bodyfield.xpathInsert(content, position, xpath,
                namespaces={'cnx': 'http://cnx.rice.edu/cnxml'})
            content = XMLTextValue(content,
                                   bodyfield.mimeType,
                                   bodyfield.outputMimeType)
            result = self.eip_transform(content)
            result = bodyfield.processingInstruction + '\n' + \
                     doctype + '\n' + result
        elif action=='update':
            bodyfield.xpathUpdate(content, xpath,
                namespaces={'cnx': 'http://cnx.rice.edu/cnxml'})
            content = XMLTextValue(content,
                                   bodyfield.mimeType,
                                   bodyfield.outputMimeType)
            result = self.eip_transform(content)
            result = bodyfield.processingInstruction + '\n' + \
                     doctype + '\n' + result
        elif action=='delete' and xpath:
            bodyfield.xpathDelete(xpath,
                namespaces={'cnx': 'http://cnx.rice.edu/cnxml'})
            result = None
        else:
            result = None

        self.request.RESPONSE.setHeader('Content-Type',
                                        'application/xhtml+xml; charset=utf-8')

        return result
Example #3
0
class TestXMLTextValue(unittest.TestCase):
    """ Test value module """
    layer = INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.value = XMLTextValue(
            raw='<html><body>test</body></html>',
            mimeType='text/xml',
            outputMimeType='text/html',
            encoding='utf-8'
        )

    def test_xmltextvalue(self):
        self.assertTrue(IXMLTextValue.providedBy(self.value))

    def test_updateFromTree(self):
        tree = etree.fromstring('<html><body><h1>heading</h1></body></html>')
        self.value._updateFromTree(tree)
        self.assertEqual(self.value.raw, '%s\n%s' % (
                                         self.value.processingInstruction,
                                         etree.tostring(tree)
                                         ))

    def test_xpathUpdate(self):
        self.value.xpathUpdate('<body><h2>Heading2</h2></body>', '/html/body')
        self.assertEqual(self.value.raw,
            '%s\n<html><body><h2>Heading2</h2></body></html>'
            % self.value.processingInstruction)

    def test_xpathDelete(self):
        self.value.xpathDelete('/html/body')
        self.assertEqual(self.value.raw, '%s\n<html/>'
            % self.value.processingInstruction)

    def test_xpathInsert(self):
        self.value.xpathInsert('<head>brain</head>', 'before', '/html/body')
        self.assertEqual(self.value.raw,
            '%s\n<html><head>brain</head><body>test</body></html>'
            % self.value.processingInstruction)

    def test_processingInstruction(self):
        self.assertEqual(self.value.processingInstruction,
            '<?xml version="1.0" encoding="UTF-8"?>')