Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
Archetypes.tests.test_file_upload.TextFieldTest Class Reference
Inheritance diagram for Archetypes.tests.test_file_upload.TextFieldTest:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.tests.test_file_upload.TextFieldTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def test_factory
def test_field
def test_get
def test_get_metadata_storage
def test_stringio_text
def test_stringio_binary
def test_file_like_text
def test_file_like_binary
def test_file_upload_text
def test_file_upload_binary
def test_real_file_text
def test_real_file_binary
def test_real_file_force_filename_detect_mime_pdf
def test_real_file_force_filename_detect_mime_xml
def test_real_file_force_filename_detect_faq
def test_real_file_force_mimetype
def test_ofs_file_text
def test_ofs_file_binary
def test_pdata_text
def test_pdata_binary
def test_string_text
def test_string_binary
def test_string_pdf
def test_base_unit_text
def test_base_unit_binary
def test_delete_file_via_set

Public Attributes

 instance
 field
 factory

Detailed Description

Definition at line 332 of file test_file_upload.py.


Member Function Documentation

Reimplemented from Archetypes.tests.test_file_upload.FileFieldTest.

Definition at line 334 of file test_file_upload.py.

00334 
00335     def afterSetUp(self):
00336         from Products.Archetypes import Field
00337         from Products.MimetypesRegistry.MimeTypesRegistry import MimeTypesRegistry
00338         from Products.PortalTransforms.TransformTool import TransformTool
00339         self.folder.mimetypes_registry = MimeTypesRegistry()
00340         self.folder.portal_transforms = TransformTool()
00341         self.folder._setOb('test_object_', BaseContent('test_object_'))
00342         self.instance = self.folder._getOb('test_object_')
00343         self.field = Field.TextField('file')
00344         self.factory = self.field.content_class

Definition at line 294 of file test_file_upload.py.

00294 
00295     def test_base_unit_binary(self):
00296         from Products.Archetypes.BaseUnit import BaseUnit
00297         f = BaseUnit('f', '\x00' + 'x' * (1 << 19), instance=self.instance)
00298         v, m, f = self.field._process_input(f, instance=self.instance)
00299         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00300         self.assertEquals(m, 'application/octet-stream')
00301         self.failIf(f)

Definition at line 286 of file test_file_upload.py.

00286 
00287     def test_base_unit_text(self):
00288         from Products.Archetypes.BaseUnit import BaseUnit
00289         f = BaseUnit('f', 'x' * (1 << 19), instance=self.instance)
00290         v, m, f = self.field._process_input(f, instance=self.instance)
00291         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00292         self.assertEquals(m, 'text/plain')
00293         self.failIf(f)

Definition at line 321 of file test_file_upload.py.

00321 
00322     def test_delete_file_via_set(self):
00323         sample = 'a sample text file to be deleted ............................'
00324         self.field.set(self.instance, sample)
00325         samplesize = self.field.get_size(self.instance)
00326         self.failUnless(samplesize > 0)
00327         deletefile = 'DELETE_FILE'
00328         self.field.set(self.instance, deletefile)
00329         samplesize = self.field.get_size(self.instance)
00330         self.failUnless(samplesize == 0)
00331 

Definition at line 345 of file test_file_upload.py.

00345 
00346     def test_factory(self):
00347         from Products.Archetypes.BaseUnit import BaseUnit
00348         self.failUnless(self.factory is BaseUnit)

Definition at line 349 of file test_file_upload.py.

00349 
00350     def test_field(self):
00351         from Products.Archetypes import Field
00352         self.failUnless(isinstance(self.field, Field.TextField))

Definition at line 99 of file test_file_upload.py.

00099 
00100     def test_file_like_binary(self):
00101         f = FileLike('\x00' + 'x' * (1 << 19))
00102         f.seek(0)
00103         v, m, f = self.field._process_input(f, instance=self.instance)
00104         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00105         self.assertEquals(m, 'application/octet-stream')
00106         self.failIf(f)

Definition at line 91 of file test_file_upload.py.

00091 
00092     def test_file_like_text(self):
00093         f = FileLike('x' * (1 << 19))
00094         f.seek(0)
00095         v, m, f = self.field._process_input(f, instance=self.instance)
00096         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00097         self.assertEquals(m, 'text/plain')
00098         self.failIf(f)

Definition at line 125 of file test_file_upload.py.

00125 
00126     def test_file_upload_binary(self):
00127         from cgi import FieldStorage
00128         from ZPublisher.HTTPRequest import FileUpload
00129         from tempfile import TemporaryFile
00130         fp = TemporaryFile('w+b')
00131         fp.write('\x00' + 'x' * (1 << 19))
00132         fp.seek(0)
00133         env = {'REQUEST_METHOD':'PUT'}
00134         headers = {'content-type':'text/plain',
00135                    'content-length': 1 << 19,
00136                    'content-disposition':'attachment; filename=test.bin'}
00137         fs = FieldStorage(fp=fp, environ=env, headers=headers)
00138         f = FileUpload(fs)
00139         v, m, f = self.field._process_input(f, instance=self.instance)
00140         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00141         self.assertEquals(m, 'application/octet-stream')
00142         self.assertEquals(f, 'test.bin')

Definition at line 107 of file test_file_upload.py.

00107 
00108     def test_file_upload_text(self):
00109         from cgi import FieldStorage
00110         from ZPublisher.HTTPRequest import FileUpload
00111         from tempfile import TemporaryFile
00112         fp = TemporaryFile('w+b')
00113         fp.write('x' * (1 << 19))
00114         fp.seek(0)
00115         env = {'REQUEST_METHOD':'PUT'}
00116         headers = {'content-type':'text/plain',
00117                    'content-length': 1 << 19,
00118                    'content-disposition':'attachment; filename=test.txt'}
00119         fs = FieldStorage(fp=fp, environ=env, headers=headers)
00120         f = FileUpload(fs)
00121         v, m, f = self.field._process_input(f, instance=self.instance)
00122         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00123         self.assertEquals(m, 'text/plain')
00124         self.assertEquals(f, 'test.txt')

Reimplemented from Archetypes.tests.test_file_upload.FileFieldTest.

Definition at line 353 of file test_file_upload.py.

00353 
00354     def test_get(self):
00355         text = 'x' * (1 << 19)
00356         self.field.set(instance=self.instance, value=text)
00357         result = self.field.get(instance=self.instance)
00358         # For TextField, we should really return a string for
00359         # backwards compatibility.
00360         self.failUnless(isinstance(result, str), type(result))

Reimplemented from Archetypes.tests.test_file_upload.FileFieldTest.

Definition at line 361 of file test_file_upload.py.

00361 
00362     def test_get_metadata_storage(self):
00363         text = 'x' * (1 << 19)
00364         self.field.storage = MetadataStorage()
00365         self.field.set(instance=self.instance, value=text)
00366         result = self.field.get(instance=self.instance)
00367         # For TextField, we should really return a string for
00368         # backwards compatibility.
00369         self.failUnless(isinstance(result, str), type(result))

Definition at line 223 of file test_file_upload.py.

00223 
00224     def test_ofs_file_binary(self):
00225         from tempfile import TemporaryFile
00226         fd = TemporaryFile('w+b')
00227         fd.write('\x00' + 'x' * (1 << 19))
00228         fd.seek(0)
00229         f = File('f', '', '')
00230         self.folder._setObject('f', f)
00231         self.folder.f.manage_upload(fd)
00232         v, m, f = self.field._process_input(self.folder.f,
00233                                             instance=self.instance)
00234         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00235         self.assertEquals(m, 'application/octet-stream')
00236         self.assertEquals(f, self.folder.f.getId())

Definition at line 207 of file test_file_upload.py.

00207 
00208     def test_ofs_file_text(self):
00209         from tempfile import TemporaryFile
00210         fd = TemporaryFile('w+b')
00211         fd.write('x' * (1 << 19))
00212         fd.seek(0)
00213         f = File('f', '', '')
00214         self.folder._setObject('f', f)
00215         self.folder.f.manage_upload(fd)
00216         self.folder.f.content_type = 'text/plain'
00217         v, m, f = self.field._process_input(self.folder.f,
00218                                             instance=self.instance)
00219         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00220         # Should retain content type.
00221         self.assertEquals(m, 'text/plain')
00222         self.assertEquals(f, self.folder.f.getId())

Definition at line 251 of file test_file_upload.py.

00251 
00252     def test_pdata_binary(self):
00253         from tempfile import TemporaryFile
00254         fd = TemporaryFile('w+b')
00255         fd.write('\x00' + 'x' * (1 << 19))
00256         fd.seek(0)
00257         f = File('f', '', '')
00258         self.folder._setObject('f', f)
00259         self.folder.f.manage_upload(fd)
00260         v, m, f = self.field._process_input(self.folder.f.data,
00261                                             instance=self.instance)
00262         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00263         self.assertEquals(m, 'application/octet-stream')
00264         self.failIf(f)

Definition at line 237 of file test_file_upload.py.

00237 
00238     def test_pdata_text(self):
00239         from tempfile import TemporaryFile
00240         fd = TemporaryFile('w+b')
00241         fd.write('x' * (1 << 19))
00242         fd.seek(0)
00243         f = File('f', '', '')
00244         self.folder._setObject('f', f)
00245         self.folder.f.manage_upload(fd)
00246         v, m, f = self.field._process_input(self.folder.f.data,
00247                                             instance=self.instance)
00248         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00249         self.assertEquals(m, 'text/plain')
00250         self.failIf(f)

Definition at line 153 of file test_file_upload.py.

00153 
00154     def test_real_file_binary(self):
00155         from tempfile import TemporaryFile
00156         fd = TemporaryFile('w+b')
00157         fd.write('\x00' + 'x' * (1 << 19))
00158         fd.seek(0)
00159         v, m, f = self.field._process_input(fd, instance=self.instance)
00160         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00161         self.assertEquals(m, 'application/octet-stream')
00162         self.failIf(f, f)

Definition at line 185 of file test_file_upload.py.

00185 
00186     def test_real_file_force_filename_detect_faq(self):
00187         from tempfile import TemporaryFile
00188         fd = TemporaryFile('w+b')
00189         fd.write('x' * (1 << 19))
00190         fd.seek(0)
00191         v, m, f = self.field._process_input(fd, instance=self.instance,
00192                                             filename='file.faq')
00193         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00194         self.assertEquals(m, 'application/octet-stream')
00195         self.assertEquals(f, 'file.faq')

Definition at line 163 of file test_file_upload.py.

00163 
00164     def test_real_file_force_filename_detect_mime_pdf(self):
00165         from tempfile import TemporaryFile
00166         fd = TemporaryFile('w+b')
00167         fd.write('\x00' + 'x' * (1 << 19))
00168         fd.seek(0)
00169         v, m, f = self.field._process_input(fd, instance=self.instance,
00170                                             filename='file.pdf')
00171         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00172         self.assertEquals(m, 'application/pdf')
00173         self.assertEquals(f, 'file.pdf')

Definition at line 174 of file test_file_upload.py.

00174 
00175     def test_real_file_force_filename_detect_mime_xml(self):
00176         from tempfile import TemporaryFile
00177         fd = TemporaryFile('w+b')
00178         fd.write('\x00' + 'x' * (1 << 19))
00179         fd.seek(0)
00180         v, m, f = self.field._process_input(fd, instance=self.instance,
00181                                             filename='file.xml')
00182         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00183         self.assertEquals(m, 'text/xml')
00184         self.assertEquals(f, 'file.xml')

Definition at line 196 of file test_file_upload.py.

00196 
00197     def test_real_file_force_mimetype(self):
00198         from tempfile import TemporaryFile
00199         fd = TemporaryFile('w+b')
00200         fd.write('\x00' + 'x' * (1 << 19))
00201         fd.seek(0)
00202         v, m, f = self.field._process_input(fd, instance=self.instance,
00203                                             mimetype='text/xml')
00204         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00205         self.assertEquals(m, 'text/xml')
00206         self.failIf(f, f)

Definition at line 143 of file test_file_upload.py.

00143 
00144     def test_real_file_text(self):
00145         from tempfile import TemporaryFile
00146         fd = TemporaryFile('w+b')
00147         fd.write('x' * (1 << 19))
00148         fd.seek(0)
00149         v, m, f = self.field._process_input(fd, instance=self.instance)
00150         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00151         self.assertEquals(m, 'text/plain')
00152         self.failIf(f, f)

Definition at line 272 of file test_file_upload.py.

00272 
00273     def test_string_binary(self):
00274         f = '\x00' + 'x' * (1 << 19)
00275         v, m, f = self.field._process_input(f, instance=self.instance)
00276         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00277         self.assertEquals(m, 'application/octet-stream')
00278         self.failIf(f)

Definition at line 279 of file test_file_upload.py.

00279 
00280     def test_string_pdf(self):
00281         f = open(os.path.join(PACKAGE_HOME, 'input', 'webdav.pdf')).read()
00282         v, m, f = self.field._process_input(f, instance=self.instance)
00283         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00284         self.assertEquals(m, 'application/pdf')
00285         self.failIf(f)

Definition at line 265 of file test_file_upload.py.

00265 
00266     def test_string_text(self):
00267         f = 'x' * (1 << 19)
00268         v, m, f = self.field._process_input(f, instance=self.instance)
00269         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00270         self.assertEquals(m, 'text/plain')
00271         self.failIf(f)

Definition at line 82 of file test_file_upload.py.

00082 
00083     def test_stringio_binary(self):
00084         from cStringIO import StringIO
00085         f = StringIO('\x00' + 'x' * (1 << 19))
00086         f.seek(0)
00087         v, m, f = self.field._process_input(f, instance=self.instance)
00088         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00089         self.assertEquals(m, 'application/octet-stream')
00090         self.failIf(f)

Definition at line 73 of file test_file_upload.py.

00073 
00074     def test_stringio_text(self):
00075         from cStringIO import StringIO
00076         f = StringIO('x' * (1 << 19))
00077         f.seek(0)
00078         v, m, f = self.field._process_input(f, instance=self.instance)
00079         self.failUnless(isinstance(v, self.factory), (type(v), self.factory))
00080         self.assertEquals(m, 'text/plain')
00081         self.failIf(f)


Member Data Documentation

Reimplemented from Archetypes.tests.test_file_upload.FileFieldTest.

Definition at line 343 of file test_file_upload.py.

Reimplemented from Archetypes.tests.test_file_upload.FileFieldTest.

Definition at line 342 of file test_file_upload.py.

Reimplemented from Archetypes.tests.test_file_upload.FileFieldTest.

Definition at line 341 of file test_file_upload.py.


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