Beispiel #1
0
 def test_image_to_ppm(self):
     self.pt.registerTransform(image_to_ppm())
     imgFile = open(input_file_path('logo.png'), 'rb')
     data = imgFile.read()
     self.assertEqual(self.mimetypes_registry.classify(data),'image/png')
     data = self.pt.convertTo(target_mimetype='image/x-portable-pixmap',orig=data)
     self.assertEqual(data.getMetadata()['mimetype'], 'image/x-portable-pixmap')
 def test_image_to_bmp(self):
     self.pt.registerTransform(image_to_bmp())
     imgFile = open(input_file_path("logo.jpg"), "rb")
     data = imgFile.read()
     self.failUnlessEqual(self.mimetypes_registry.classify(data), "image/jpeg")
     data = self.pt.convertTo(target_mimetype="image/x-ms-bmp", orig=data)
     self.failUnlessEqual(data.getMetadata()["mimetype"], "image/x-ms-bmp")
Beispiel #3
0
 def test_image_to_tiff(self):
     self.pt.registerTransform(image_to_tiff())
     imgFile = open(input_file_path('logo.jpg'), 'rb')
     data = imgFile.read()
     self.assertEqual(self.mimetypes_registry.classify(data), 'image/jpeg')
     data = self.pt.convertTo(target_mimetype='image/tiff', orig=data)
     self.assertEqual(data.getMetadata()['mimetype'], 'image/tiff')
Beispiel #4
0
 def test_image_to_bmp(self):
     self.pt.registerTransform(image_to_bmp())
     imgFile = open(input_file_path('logo.jpg'), 'rb')
     data = imgFile.read()
     self.failUnlessEqual(self.portal.mimetypes_registry.classify(data),'image/jpeg')
     data = self.pt.convertTo(target_mimetype='image/x-ms-bmp',orig=data)
     self.failUnlessEqual(data.getMetadata()['mimetype'], 'image/x-ms-bmp')
Beispiel #5
0
 def test_image_to_gif(self):
     self.pt.registerTransform(image_to_gif())
     imgFile = open(input_file_path('logo.png'), 'rb')
     data = imgFile.read()
     self.assertEqual(self.mimetypes_registry.classify(data),'image/png')
     data = self.pt.convertTo(target_mimetype='image/gif',orig=data)
     self.assertEqual(data.getMetadata()['mimetype'], 'image/gif')
Beispiel #6
0
 def testAdaptFile(self):
     file = open(input_file_path("rest1.rst"))
     data, filename, mt = self.registry(file)
     # this test that data has been adaped and file seeked to 0
     self.failUnlessEqual(data, file.read())
     file.close()
     self.failUnlessEqual(filename, "rest1.rst")
     self.assertEqual(str(mt), 'text/x-rst')
    def test_invalid_tags(self):
        from Products.PortalTransforms.libtransforms.utils import scrubHTMLNoRaise, scrubHTML
        from Products.PortalTransforms.libtransforms.utils import IllegalHTML

        htmlFile = open(input_file_path("test_invalid_tags.html"), "rb")
        data = htmlFile.read()
        self.assertRaises(IllegalHTML, scrubHTML, data)
        self.assertRaises(IllegalHTML, scrubHTMLNoRaise, data)
Beispiel #8
0
 def test_image_to_pcx(self):
     self.pt.registerTransform(image_to_pcx())
     imgFile = open(input_file_path('logo.gif'), 'rb')
     data = imgFile.read()
     self.failUnlessEqual(self.mimetypes_registry.classify(data),
                          'image/gif')
     data = self.pt.convertTo(target_mimetype='image/pcx', orig=data)
     self.failUnlessEqual(data.getMetadata()['mimetype'], 'image/pcx')
    def test_javascript_uri(self):
        from Products.PortalTransforms.libtransforms.utils import scrubHTMLNoRaise, scrubHTML
        from Products.PortalTransforms.libtransforms.utils import IllegalHTML

        htmlFile = open(input_file_path("test_js_uri.html"), "rb")
        data = htmlFile.read()
        self.assertRaises(IllegalHTML, scrubHTML, data)
        result = scrubHTMLNoRaise(data)
        self.assertTrue("link" in result)
Beispiel #10
0
    def test_invalid_tags(self):
        from Products.PortalTransforms.libtransforms.utils import (
            scrubHTMLNoRaise, scrubHTML)
        from Products.PortalTransforms.libtransforms.utils import IllegalHTML

        htmlFile = open(input_file_path('test_invalid_tags.html'), 'rb')
        data = htmlFile.read()
        self.assertRaises(IllegalHTML, scrubHTML, data)
        self.assertRaises(IllegalHTML, scrubHTMLNoRaise, data)
 def test_abc_to_pdf(self):
     fd = open(input_file_path('DonaldBlue.abc'), "r")
     abc = fd.read()
     fd.close()
     got = self.pt.convertTo('application/pdf',
                             abc)
     got_meta = got.getMetadata()
     print 'metadata returned : ' + str(got_meta)
     # self.assertEqual(got.getData(), ps)
     self.assertEqual(got_meta['mimetype'], 'application/pdf')
Beispiel #12
0
    def test_javascript_uri(self):
        from Products.PortalTransforms.libtransforms.utils import (
            scrubHTMLNoRaise, scrubHTML)
        from Products.PortalTransforms.libtransforms.utils import IllegalHTML

        htmlFile = open(input_file_path('test_js_uri.html'), 'rb')
        data = htmlFile.read()
        self.assertRaises(IllegalHTML, scrubHTML, data)
        result = scrubHTMLNoRaise(data)
        self.assertTrue('link' in result)
Beispiel #13
0
    def test_javascript_on_attr(self):
        from Products.PortalTransforms.libtransforms.utils import (
                scrubHTMLNoRaise, scrubHTML)
        from Products.PortalTransforms.libtransforms.utils import IllegalHTML

        htmlFile = open(input_file_path('test_js_on.html'), 'rb')
        data = htmlFile.read()
        self.assertRaises(IllegalHTML, scrubHTML, data)
        result = scrubHTMLNoRaise(data)
        self.assertTrue('link' in result)
 def test_abc_to_mp3(self):
     fd = open(input_file_path('DonaldBlue.abc'), "r")
     abc = fd.read()
     # print self.mtr.classify(abc)
     fdmp3 = open(output_file_path('DonaldBlue1.mp3'), "rb")
     mp3 = fdmp3.read()
     fdmp3.close()
     got = self.pt.convertTo('audio/mpeg',
                             abc)
     got_meta = got.getMetadata()
     print 'metadata returned : ' + str(got_meta)
     self.assertEqual(mp3, got.getData())
     self.assertEqual(got_meta['mimetype'], 'audio/mpeg')
     """
    def test_abc_to_png(self):
        fabc = open(input_file_path('DonaldBlue.abc'), "rb")
        abc = fabc.read()
        fabc.close()

        got = self.pt.convertTo('image/png',
                                abc,
                                mimetype='text/vnd.abc')
        got_meta = got.getMetadata()
        print 'metadata returned : ' + str(got_meta)
        # self.assertEqual(ps, got.getData())
        """ """
        self.assertEqual(got_meta['mimetype'], 'image/png')
        fdgot = open(output_file_path('got.png'), "wb")
        fdgot.write(got.getData())
        fdgot.close()
        """ """
Beispiel #16
0
 def test_guessMime(self):
     for filename, expected in samplefiles:
         file = open(input_file_path(filename))
         data = file.read()
         file.close()
         
         # use method direct
         got = guessMime(data)
         self.failUnlessEqual(got, expected)
         
         # use mtr-tool
         got_from_tool = self.registry.classify(data)
         self.failUnlessEqual(got_from_tool, expected)            
         
         # now cut it to the first 8k if greater
         if len(data) > 8192:
             data=data[:8192]
             got_cutted = self.registry.classify(data)
             self.failUnlessEqual(got_cutted, expected)          
 def test_abc_to_ps(self):
     """
     .. note: Because creation date, command line, filenames, etc...
         are part of postscript file, it isn't possible to compare
         files !!! ;-(
     """
     fd = open(input_file_path('DonaldBlue.abc'), "r")
     abc = fd.read()
     fd.close()
     """
     fdps = open(output_file_path('DonaldBlue.ps'), "rb")
     ps = fdps.read()
     fdps.close()
     """
     got = self.pt.convertTo('application/postscript',
                             abc)
     got_meta = got.getMetadata()
     print 'metadata returned : ' + str(got_meta)
     # self.assertEqual(got.getData(), ps)
     self.assertEqual(got_meta['mimetype'], 'application/postscript')
Beispiel #18
0
from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase

from utils import input_file_path
FILE_PATH = input_file_path("demo1.pdf")


class TestGraph(ATSiteTestCase):
    def afterSetUp(self):
        ATSiteTestCase.afterSetUp(self)
        self.engine = self.portal.portal_transforms

    def testGraph(self):
        data = open(FILE_PATH, 'r').read()
        requirements = self.engine._policies.get('text/plain', [])
        if requirements:
            out = self.engine.convertTo('text/plain', data, filename=FILE_PATH)
            self.failUnless(out.getData())

    def testFindPath(self):
        originalMap = self.engine._mtmap
        """
        The dummy map used for this test corresponds to a graph
        depicted in ASCII art below :
        
        +---+
        |   |
        |   v
        +-->1<-->2-->4-->6<--7
            ^    ^   |
            |    |   |
            v    |   |
Beispiel #19
0
 class TransformTestSubclass(TransformTest):
     input = input_file_path(tr_input)
     output = output_file_path(tr_output)
     transform = _transform
     normalize = lambda x, y: _normalize(y)
     subobjects = _subobjects
Beispiel #20
0
 def test_invalid_tags(self):
     htmlFile = open(input_file_path('test_invalid_tags.html'), 'rb')
     data = htmlFile.read()
     self.assertEqual(scrubHTMLNoRaise(data).strip(), '')
Beispiel #21
0
 def test_ignore_javascript_attrs(self):
     wordFile = open(input_file_path('test_js.doc'), 'rb')
     data = wordFile.read()
     # should not throw exception even though it holds javascript link
     data = self.pt.convertTo(target_mimetype='text/html', orig=data)
Beispiel #22
0
 def test_ignore_javascript_attrs(self):
     wordFile = open(input_file_path('test_js.doc'), 'rb')
     data = wordFile.read()
     # should not throw exception even though it holds javascript link
     data = self.pt.convertTo(target_mimetype='text/html',
                              orig=data)
Beispiel #23
0
 def test_javascript_uri(self):
     htmlFile = open(input_file_path('test_js_uri.html'), 'rb')
     data = htmlFile.read()
     result = scrubHTMLNoRaise(data)
     self.assertTrue('link' in result)
Beispiel #24
0
from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase

from utils import input_file_path
FILE_PATH = input_file_path("demo1.pdf")

class TestGraph(ATSiteTestCase):

    def afterSetUp(self):
        ATSiteTestCase.afterSetUp(self)
        self.engine = self.portal.portal_transforms

    def testGraph(self):
        data = open(FILE_PATH, 'r').read()
        requirements = self.engine._policies.get('text/plain', [])
        if requirements:
            out = self.engine.convertTo('text/plain', data, filename=FILE_PATH)
            self.assertTrue(out.getData())

    def testFindPath(self):
        originalMap = self.engine._mtmap
        """
        The dummy map used for this test corresponds to a graph
        depicted in ASCII art below :
        
        +---+
        |   |
        |   v
        +-->1<-->2-->4-->6<--7
            ^    ^   |
            |    |   |
            v    |   |
 def test_mimetype_abc(self):
     fd = open(input_file_path('DonaldBlue.abc'), "r")
     abc = fd.read()
     self.assertEqual(self.mtr.classify(abc), 'text/vnd.abc')