Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
PortalTransforms.tests.test_engine.TestEngine Class Reference
Inheritance diagram for PortalTransforms.tests.test_engine.TestEngine:
Inheritance graph
[legend]
Collaboration diagram for PortalTransforms.tests.test_engine.TestEngine:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def register
def testRegister
def testFailRegister
def testCall
def testConvert
def testConvertTo
def testChain
def testPolicy
def testSame
def testCache

Public Attributes

 engine
 data

Detailed Description

Definition at line 97 of file test_engine.py.


Member Function Documentation

Definition at line 99 of file test_engine.py.

00099 
00100     def afterSetUp(self):
00101         ATSiteTestCase.afterSetUp(self)
00102         self.engine = self.portal.portal_transforms
00103         self.data = '<b>foo</b>'

Definition at line 104 of file test_engine.py.

00104 
00105     def register(self):
00106         #A default set of transforms to prove the interfaces work
00107         self.engine.registerTransform(HtmlToText())
00108         self.engine.registerTransform(FooToBar())

Here is the caller graph for this function:

Definition at line 210 of file test_engine.py.

00210 
00211     def testCache(self):
00212         data = "This is a test"
00213         other_data = 'some different data'
00214         mt = "text/plain"
00215         self.engine.max_sec_in_cache = 20
00216         out = self.engine.convertTo(mt, data, mimetype=mt, object=self)
00217         self.failUnlessEqual(out.getData(), data, out.getData())
00218         out = self.engine.convertTo(mt, other_data, mimetype=mt, object=self)
00219         self.failUnlessEqual(out.getData(), data, out.getData())
00220         self.engine.max_sec_in_cache = -1
00221         out = self.engine.convertTo(mt, data, mimetype=mt, object=self)
00222         self.failUnlessEqual(out.getData(), data, out.getData())
00223         out = self.engine.convertTo(mt, other_data, mimetype=mt, object=self)
00224         self.failUnlessEqual(out.getData(), other_data, out.getData())
00225 

Definition at line 121 of file test_engine.py.

00121 
00122     def testCall(self):
00123         self.register()
00124         data = self.engine('HtmlToText', self.data)
00125         self.failUnlessEqual(data, "foo")
00126 
00127         data = self.engine('FooToBar', self.data)
00128         self.failUnlessEqual(data, "<b>bar</b>")

Here is the call graph for this function:

Definition at line 164 of file test_engine.py.

00164 
00165     def testChain(self):
00166         self.register()
00167         hb = chain('hbar')
00168         hb.registerTransform(HtmlToText())
00169         hb.registerTransform(FooToBar())
00170 
00171         self.engine.registerTransform(hb)
00172         cache = self.engine.convert('hbar', self.data)
00173         self.failUnlessEqual(cache.getData(), "bar")
00174         self.failUnlessEqual(cache.name(), "hbar")

Here is the call graph for this function:

Definition at line 129 of file test_engine.py.

00129 
00130     def testConvert(self):
00131         self.register()
00132 
00133         data = self.engine.convert('HtmlToText', self.data)
00134         self.failUnlessEqual(data.getData(), "foo")
00135         self.failUnlessEqual(data.getMetadata()['mimetype'], 'text/plain')
00136         self.failUnlessEqual(data.getMetadata().get('encoding'), None)
00137         self.failUnlessEqual(data.name(), "HtmlToText")
00138 
00139         self.engine.registerTransform(HtmlToTextWithEncoding())
00140         data = self.engine.convert('HtmlToTextWithEncoding', self.data)
00141         self.failUnlessEqual(data.getMetadata()['mimetype'], 'text/plain')
00142         self.failUnlessEqual(data.getMetadata()['encoding'], 'ascii')
00143         self.failUnlessEqual(data.name(), "HtmlToTextWithEncoding")

Here is the call graph for this function:

Definition at line 144 of file test_engine.py.

00144 
00145     def testConvertTo(self):
00146         self.register()
00147 
00148         data = self.engine.convertTo('text/plain', self.data, mimetype="text/html")
00149         self.failUnlessEqual(data.getData(), "foo")
00150         self.failUnlessEqual(data.getMetadata()['mimetype'], 'text/plain')
00151         self.failUnlessEqual(data.getMetadata().get('encoding'), None)
00152         self.failUnlessEqual(data.name(), "text/plain")
00153 
00154         self.engine.unregisterTransform('HtmlToText')
00155         self.engine.unregisterTransform('FooToBar')
00156         self.engine.registerTransform(HtmlToTextWithEncoding())
00157         data = self.engine.convertTo('text/plain', self.data, mimetype="text/html")
00158         self.failUnlessEqual(data.getMetadata()['mimetype'], 'text/plain')
00159         # HtmlToTextWithEncoding. Now None is the right 
00160         #self.failUnlessEqual(data.getMetadata()['encoding'], 'ascii')
00161         # XXX the new algorithm is choosing html_to_text instead of 
00162         self.failUnlessEqual(data.getMetadata()['encoding'], None)
00163         self.failUnlessEqual(data.name(), "text/plain")

Here is the call graph for this function:

Definition at line 112 of file test_engine.py.

00112 
00113     def testFailRegister(self):
00114         register = self.engine.registerTransform
00115         self.assertRaises(TransformException, register, TransformNoIO())
00116         self.assertRaises(TransformException, register, BadTransformMissingImplements())
00117         self.assertRaises(TransformException, register, BadTransformBadMIMEType1())
00118         self.assertRaises(TransformException, register, BadTransformBadMIMEType2())
00119         self.assertRaises(TransformException, register, BadTransformNoInput())
00120         self.assertRaises(TransformException, register, BadTransformWildcardOutput())

Definition at line 175 of file test_engine.py.

00175 
00176     def testPolicy(self):
00177         mt = 'text/x-html-safe'
00178         data = '<script>this_is_unsafe();</script><p>this is safe</p>'
00179         
00180         cache = self.engine.convertTo(mt, data, mimetype='text/html')
00181         self.failUnlessEqual(cache.getData(), '<p>this is safe</p>')
00182 
00183         self.engine.registerTransform(DummyHtmlFilter1())
00184         self.engine.registerTransform(DummyHtmlFilter2())
00185         required = ['dummy_html_filter1', 'dummy_html_filter2']
00186 
00187         self.engine.manage_addPolicy(mt, required)
00188         expected_policy = [('text/x-html-safe',
00189                             ('dummy_html_filter1', 'dummy_html_filter2'))]
00190         self.failUnlessEqual(self.engine.listPolicies(), expected_policy)
00191 
00192         cache = self.engine.convertTo(mt, data, mimetype='text/html')
00193         self.failUnlessEqual(cache.getData(), '<div class="dummy"><span class="dummy"><p>this is safe</p></span></div>')
00194 
00195         self.failUnlessEqual(cache.getMetadata()['mimetype'], mt)
00196         self.failUnlessEqual(cache.name(), mt)
00197 
00198         path = self.engine._findPath('text/html', mt, required)
00199         self.failUnlessEqual(str(path),
00200                              "[<Transform at dummy_html_filter1>, "
00201                              "<Transform at dummy_html_filter2>, "
00202                              "<Transform at safe_html>]")

Definition at line 109 of file test_engine.py.

00109 
00110     def testRegister(self):
00111         self.register()

Here is the call graph for this function:

Definition at line 203 of file test_engine.py.

00203 
00204     def testSame(self):
00205         data = "This is a test"
00206         mt = "text/plain"
00207         out = self.engine.convertTo('text/plain', data, mimetype=mt)
00208         self.failUnlessEqual(out.getData(), data)
00209         self.failUnlessEqual(out.getMetadata()['mimetype'], 'text/plain')


Member Data Documentation

Definition at line 102 of file test_engine.py.

Definition at line 101 of file test_engine.py.


The documentation for this class was generated from the following file: