Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
MimetypesRegistry.tests.test_mimetypes.TestMimeTypesclass Class Reference
Inheritance diagram for MimetypesRegistry.tests.test_mimetypes.TestMimeTypesclass:
Inheritance graph
[legend]
Collaboration diagram for MimetypesRegistry.tests.test_mimetypes.TestMimeTypesclass:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def testClassify
def testExtension
def testFDOGlobs
def testLookup
def testAdaptMt
def testAdaptFile
def testAdaptData

Public Attributes

 registry

Detailed Description

Definition at line 9 of file test_mimetypes.py.


Member Function Documentation

Definition at line 11 of file test_mimetypes.py.

00011 
00012     def afterSetUp(self):
00013         ATSiteTestCase.afterSetUp(self)
00014         self.registry = self.portal.mimetypes_registry

Definition at line 154 of file test_mimetypes.py.

00154 
00155     def testAdaptData(self):
00156         data, filename, mt = self.registry('<?xml ?>')
00157         # this test that data has been adaped and file seeked to 0
00158         self.failUnlessEqual(data, '<?xml ?>')
00159         self.failUnlessEqual(filename, None)
00160         self.failUnless(isinstance(mt, text_xml), str(mt))
00161 

Definition at line 145 of file test_mimetypes.py.

00145 
00146     def testAdaptFile(self):
00147         file = open(input_file_path("rest1.rst"))
00148         data, filename, mt = self.registry(file)
00149         # this test that data has been adaped and file seeked to 0
00150         self.failUnlessEqual(data, file.read())
00151         file.close()
00152         self.failUnlessEqual(filename, "rest1.rst")
00153         self.assertEqual(str(mt), 'text/x-rst')

Here is the call graph for this function:

Definition at line 138 of file test_mimetypes.py.

00138 
00139     def testAdaptMt(self):
00140         data, filename, mt = self.registry('bar', mimetype='text/xml')
00141         # this test that data has been adaped and file seeked to 0
00142         self.failUnlessEqual(data, 'bar')
00143         self.failUnlessEqual(filename, None)
00144         self.failUnless(isinstance(mt, text_xml), str(mt))

Definition at line 15 of file test_mimetypes.py.

00015 
00016     def testClassify(self):
00017         reg = self.registry
00018         c = reg._classifiers()
00019         self.failUnless(c[0].name().startswith("Extensible Markup Language"),
00020                         c[0].name())
00021 
00022         #Real XML
00023         data = "<?xml version='1.0'?><foo>bar</foo>"
00024         mt = reg.classify(data)
00025         self.failUnless(isinstance(mt, text_xml), str(mt))
00026 
00027         # with leading whitespace (http://dev.plone.org/archetypes/ticket/622)
00028         # still valid xml
00029         data = " <?xml version='1.0'?><foo>bar</foo>"
00030         mt = reg.classify(data)
00031         self.failUnless(isinstance(mt, text_xml), str(mt))
00032         
00033         # also #622: this is not xml
00034         data = 'xml > plain text'
00035         mt = reg.classify(data)
00036         self.failUnless(str(mt) != 'text/xml')
00037 
00038         #Passed in MT
00039         mt = reg.classify(data, mimetype="text/plain")
00040         self.failUnless(isinstance(mt, text_plain), str(mt))
00041 
00042         #Passed in filename
00043         mt = reg.classify(data, filename="test.xml")
00044         self.failUnless(isinstance(mt, text_xml), str(mt))
00045         mt = reg.classify(data, filename="test.jpg")
00046         self.failUnlessEqual(str(mt), 'image/jpeg')
00047 
00048         # use xml classifier
00049         mt = reg.classify('<?xml ?>')
00050         self.failUnless(isinstance(mt, text_xml), str(mt))
00051 
00052         # test no data return default
00053         mt = reg.classify('')
00054         self.failUnless(isinstance(mt, text_plain), str(mt))
00055         reg.defaultMimetype = 'text/xml'
00056         mt = reg.classify('')
00057         self.failUnless(isinstance(mt, text_xml), str(mt))
00058 
00059         # test unclassifiable data and no stream flag (filename)
00060         mt = reg.classify('xxx')
00061         self.failUnless(isinstance(mt, text_plain), str(mt))
00062 
00063         # test unclassifiable data and file flag
00064         mt = reg.classify('baz', filename='xxx')
00065         self.failUnless(isinstance(mt, application_octet_stream), str(mt))

Definition at line 66 of file test_mimetypes.py.

00066 
00067     def testExtension(self):
00068         reg = self.registry
00069         data = "<foo>bar</foo>"
00070         mt = reg.lookupExtension(filename="test.xml")
00071         self.failUnless(isinstance(mt, text_xml), str(mt))
00072 
00073         mt = reg.classify(data, filename="test.foo")
00074         self.failUnless(isinstance(mt, application_octet_stream), str(mt))
00075 
00076         mt = reg.classify(data, filename="test.tgz")
00077         self.failUnlessEqual(str(mt), 'application/x-tar')
00078 
00079         mt = reg.classify(data, filename="test.tar.gz")
00080         self.failUnlessEqual(str(mt), 'application/x-tar')
00081 
00082         mt = reg.classify(data, filename="test.pdf.gz")
00083         self.failUnlessEqual(str(mt), 'application/pdf')

Definition at line 84 of file test_mimetypes.py.

00084 
00085     def testFDOGlobs(self):
00086         # The mime types here might only match if they match a glob on
00087         # the freedesktop.org registry.
00088         data = ''
00089         reg = self.registry
00090         mt = reg.classify(data, filename="test.anim1")
00091         self.failUnlessEqual(str(mt), 'video/x-anim')
00092 
00093         mt = reg.classify(data, filename="test.ini~")
00094         self.failUnlessEqual(str(mt), 'application/x-trash')
00095 
00096         mt = reg.classify(data, filename="test.ini%")
00097         self.failUnlessEqual(str(mt), 'application/x-trash')
00098 
00099         mt = reg.classify(data, filename="test.ini.bak")
00100         self.failUnlessEqual(str(mt), 'application/x-trash')
00101 
00102         mt = reg.classify(data, filename="test.f90")
00103         self.failUnlessEqual(str(mt), 'text/x-fortran')
00104 
00105         mt = reg.classify(data, filename="test.f95")
00106         self.failUnlessEqual(str(mt), 'text/x-fortran')
00107 
00108         mt = reg.classify(data, filename="makefile")
00109         self.failUnlessEqual(str(mt), 'text/x-makefile')
00110 
00111         mt = reg.classify(data, filename="Makefile")
00112         self.failUnlessEqual(str(mt), 'text/x-makefile')
00113 
00114         mt = reg.classify(data, filename="makefile.ac")
00115         self.failUnlessEqual(str(mt), 'text/x-makefile')
00116 
00117         mt = reg.classify(data, filename="makefile.in")
00118         self.failUnlessEqual(str(mt), 'text/x-makefile')
00119 
00120         mt = reg.classify(data, filename="AUTHORS")
00121         self.failUnlessEqual(str(mt), 'text/x-authors')
00122 
00123         mt = reg.classify(data, filename="INSTALL")
00124         self.failUnlessEqual(str(mt), 'text/x-install')

Definition at line 125 of file test_mimetypes.py.

00125 
00126     def testLookup(self):
00127         reg = self.registry
00128         mt = reg.lookup('text/plain')
00129         self.failUnless(isinstance(mt[0], text_plain), str(mt[0]))
00130 
00131         # Test lookup of aliases in SMI database (see smi_mimetypes)
00132         mt1 = reg.lookup('application/vnd.wordperfect')
00133         mt2 = reg.lookup('application/wordperfect')
00134         self.assertEqual(mt1, mt2)
00135 
00136         mt = reg.lookup('text/notexistent')
00137         self.failUnlessEqual(mt, ())


Member Data Documentation

Definition at line 13 of file test_mimetypes.py.


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