Пример #1
0
class ViewTests(TestBase):

    def setUp(self):
        super(ViewTests, self).setUp()
        self.registry = TransformerRegistry()
        self.registry.registry.clear()

    def _register_one(self):
        self.registry.register_transformation(
            'demo', 'play.xsl', os.path.join(cwd, 'play.xsl'), 'XSLT1')

    def test_transformer_registry_view_unauthorized(self):
        with self.assertRaises(zExceptions.Unauthorized):
            self.portal.restrictedTraverse('@@transformer-registry')

    def test_transformer_registry_view(self):
        self.login('god')
        view = self.portal.restrictedTraverse('@@transformer-registry')
        view()

    def test_transformer_registry_detail_view_unauthorized(self):
        with self.assertRaises(zExceptions.Unauthorized):
            self.portal.restrictedTraverse('@@transformer-registry-view')

    def test_transformer_registry_detail_view(self):
        self._register_one()
        self.login('god')
        Testing.makerequest.makerequest(self.portal)
        view = self.portal.restrictedTraverse('@@transformer-registry-view')
        self.portal.REQUEST.form['family'] = 'demo'
        self.portal.REQUEST.form['name'] = 'play.xsl'
        view()
Пример #2
0
 def setUp(self):
     self.registry = TransformerRegistry()
     self.registry.clear()
     self.registry.register_transformation('demo', 't1', python_transformer,
                                           'python')
     self.registry.register_transformation('demo', 't2',
                                           python_transformer2, 'python')
     self.registry.register_transformation('demo', 'catalog-xsl',
                                           catalog_xsl, 'XSLT1')
     self.registry.register_transformation('demo', 'sample-xslt2',
                                           sample_xslt2, 'XSLT2')
     self.registry.register_transformation('demo', 'catalog-python',
                                           catalog_transformer, 'python')
Пример #3
0
 def setUp(self):
     super(ViewTests, self).setUp()
     self.registry = TransformerRegistry()
     self.registry.registry.clear()
Пример #4
0
 def setUp(self):
     self.registry = TransformerRegistry()
     self.registry.registry.clear()
Пример #5
0
class BasicTests(unittest2.TestCase):

    def setUp(self):
        self.registry = TransformerRegistry()
        self.registry.registry.clear()

    def _register_one(self):
        self.registry.register_transformation(
            'demo', 'play.xsl', os.path.join(cwd, 'play.xsl'), 'XSLT1')

    def test_register(self):
        self._register_one()

    def test_register_twice(self):
        self._register_one()
        with self.assertRaises(ValueError):
            self._register_one()

    def test_register_unsupported_transformer_type(self):
        with self.assertRaises(ValueError):
            self.registry.register_transformation(
                'demo', 'play.xsl', os.path.join(cwd, 'play.xsl'), 'XXXXXXXXXX')

    def test_register_invalid_xml_transformer(self):
        with self.assertRaises(ValueError):
            self.registry.register_transformation(
                'demo', 'play.xsl', os.path.join(cwd, 'play-invalid-xml.xsl'), 'XSLT1')

    def test_register_invalid_xslt_transformer(self):
        with self.assertRaises(ValueError):
            self.registry.register_transformation(
                'demo', 'play.xsl', os.path.join(cwd, 'play-invalid-xslt.xsl'), 'XSLT1')

    def test_register_nonexisting_transformer(self):
        with self.assertRaises(ValueError):
            self.registry.register_transformation(
                'demo', 'play.xsl', 'does.not.exist.xsl', 'XSLT1')

    def test_registry_clear(self):
        self._register_one()
        self.registry.clear()
        self.assertEqual(len(self.registry), 0)

    def test_registry_get_existing_xslt(self):
        self._register_one()
        self.registry.get_transformation('demo', 'play.xsl')

    def test_registry_get_nonexisting_xslt(self):
        self._register_one()
        with self.assertRaises(ValueError):
            self.registry.get_transformation('xxx', 'xxx')

    def test_register_python_transformer(self):
        self.registry.register_transformation(
            'demo', 'foo2bar replacer', python_transformer, 'python')

    def test_register_xslt2(self):
        self.registry.register_transformation(
            'xslt2', 'sample_xslt2.xsl', os.path.join(cwd, 'sample_xslt2.xsl'), 'XSLT2')
Пример #6
0
class BasicTests(unittest2.TestCase):
    def setUp(self):
        self.registry = TransformerRegistry()
        self.registry.clear()
        self.registry.register_transformation('demo', 't1', python_transformer,
                                              'python')
        self.registry.register_transformation('demo', 't2',
                                              python_transformer2, 'python')
        self.registry.register_transformation('demo', 'catalog-xsl',
                                              catalog_xsl, 'XSLT1')
        self.registry.register_transformation('demo', 'sample-xslt2',
                                              sample_xslt2, 'XSLT2')
        self.registry.register_transformation('demo', 'catalog-python',
                                              catalog_transformer, 'python')

    def test_verify_steps_working(self):
        T = Transformer([('demo', 't1'), ('demo', 't2')],
                        transformer_registry=self.registry)
        T.verify_steps()

    def test_verify_steps_failing(self):
        T = Transformer([('xxx', 'yyy')], transformer_registry=self.registry)
        with self.assertRaises(ValueError):
            T.verify_steps()

    def test_transformation_1(self):
        T = Transformer([('demo', 't1')], transformer_registry=self.registry)
        result = T(sample_xml)
        self.assertTrue(result.count('<bar>') == 3)

    def test_transformation_with_node(self):
        T = Transformer([('demo', 't1')], transformer_registry=self.registry)
        result = T(lxml.etree.fromstring(sample_xml))
        self.assertTrue(result.count('<bar>') == 3)

    def test_transformation_improper_root(self):
        T = Transformer([('demo', 't1')], transformer_registry=self.registry)
        with self.assertRaises(TypeError):
            T(object)

    def test_transformation_unicode_without_input_encoding(self):
        T = Transformer([('demo', 't1')], transformer_registry=self.registry)
        with self.assertRaises(TypeError):
            T(sample_xml.encode('utf8'), input_encoding=None)

    def test_transformation_2(self):
        T = Transformer([('demo', 't2')], transformer_registry=self.registry)
        result = T(sample_xml)
        self.assertTrue('<hello foo="bar">' in result)

    def test_transformation_return_fragment(self):
        T = Transformer([('demo', 't1')], transformer_registry=self.registry)
        result = T(sample_xml, return_fragment='world')
        self.assertTrue('<hello' not in result)

    def test_transformation_return_fragment_non_existing_fragment(self):
        T = Transformer([('demo', 't1')], transformer_registry=self.registry)
        with self.assertRaises(ValueError):
            T(sample_xml, return_fragment='XXXXXX')

    def test_transformation_custom_output_encoding(self):
        T = Transformer([('demo', 't1')], transformer_registry=self.registry)
        result = T(sample_xml, output_encoding='utf16')
        self.assertTrue(not isinstance(result, unicode))

    def test_transformation_1_and_2(self):
        T = Transformer([('demo', 't1'), ('demo', 't2')],
                        transformer_registry=self.registry)
        result = T(sample_xml)
        self.assertTrue(result.count('<foo>') == 0)
        self.assertTrue(result.count('<bar>') == 3)
        self.assertTrue('<hello foo="bar">' in result)

    def test_catalog_xsd(self):
        T = Transformer([('demo', 'catalog-xsl')],
                        transformer_registry=self.registry)
        result = T(catalog_xml)
        self.assertTrue('<h2>My CD Collection</h2>' in result)
        self.assertTrue('<tr bgcolor="#9acd32">' in result)
        self.assertTrue('<td>Bob Dylan</td>' in result)

    def test_catalog_xsd_python_transform(self):
        T = Transformer([('demo', 'catalog-xsl'), ('demo', 'catalog-python')],
                        transformer_registry=self.registry)
        result = T(catalog_xml)
        self.assertTrue('<h2>My CD Collection</h2>' in result)
        self.assertTrue('<tr bgcolor="#9acd32">' in result)
        self.assertFalse('<table>' in result)
        self.assertTrue('<TABELLE' in result)

    def test_transformation_with_debug_option(self):
        T = Transformer([('demo', 'catalog-xsl'), ('demo', 'catalog-python')],
                        transformer_registry=self.registry)
        T(catalog_xml, debug=True)

    def test_catalog_python_xsd_transform(self):
        T = Transformer([('demo', 'catalog-python'), ('demo', 'catalog-xsl')],
                        transformer_registry=self.registry)
        result = T(catalog_xml)
        # running catalog-python first should not have any effect
        self.assertTrue('<h2>My CD Collection</h2>' in result)
        self.assertTrue('<tr bgcolor="#9acd32">' in result)
        self.assertTrue('<table' in result)

    def test_xslt2_transformation(self):
        T = Transformer([('demo', 'sample-xslt2')],
                        transformer_registry=self.registry)
        result = T(sample_xslt2_xml)
        self.assertTrue('<test xmlns="http://www.example.com/v2">' in result)