Changeset 4272 for waeup/branches


Ignore:
Timestamp:
13 Jun 2009, 10:38:07 (16 years ago)
Author:
uli
Message:

Add first functional upload tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/browser.txt

    r4232 r4272  
    115115  >>> browser.getLink('Data Center').click()
    116116
    117 By default we have a directory in the sources for upload:
     117Setting the file path
     118---------------------
     119
     120A datacenter stores files in a path in filesystem. By default this is
     121a directory in the sources:
    118122
    119123  >>> print browser.contents
     
    123127  ...
    124128
     129Going to 'Settings` we can change the path:
     130
     131  >>> browser.getLink('Settings').click()
     132  >>> pathsetting = browser.getControl(name='newpath')
     133
     134We create a directory and set it as our upload path:
     135
     136  >>> import os
     137  >>> cwd = os.getcwd()
     138  >>> uploadpath = os.path.join(cwd, 'testfiles')
     139  >>> os.mkdir(uploadpath)
     140  >>> pathsetting.value = uploadpath
     141
     142And submit the form:
     143
     144  >>> browser.getControl(name='save').click()
     145
     146We clean up the set directory path, as there might be some files be
     147copied some files from installation:
     148
     149  >>> files = os.listdir(uploadpath)
     150  >>> for filename in files:
     151  ...   os.unlink(os.path.join(uploadpath, filename))
     152
     153The new upload directory is now empty:
     154
     155  >>> os.listdir(uploadpath)
     156  []
     157
     158Now we can upload files. Most interesting files might be CSV files,
     159that can be imported lateron. We create a CSV file containing faculty
     160descriptions:
     161
     162  >>> open('faculties.csv', 'wb').write(
     163  ... """code,title,title_prefix
     164  ... FA,Arts,Faculty
     165  ... FS,Sciences,Faculty
     166  ... """)
     167
     168Now we can upload this file. To do this, we first go to the upload
     169page:
     170
     171  >>> browser.getLink('Upload data').click()
     172
     173and enter the appropriate data in the form:
     174
     175  >>> filewidget = browser.getControl(name='uploadfile:file')
     176  >>> filewidget
     177  <Control name='uploadfile:file' type='file'>
     178 
     179A sidenote for developers: by marking the filewidget with the
     180``:file`` extension, we tell Zope to handle this field as a file
     181widget.
     182
     183  >>> import cStringIO
     184  >>> filecontents = cStringIO.StringIO(
     185  ...   open('faculties.csv', 'rb').read())
     186  >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv')
     187 
     188  >>> browser.getControl(name='SUBMIT').click()
     189
     190The file was indeed uploaded:
     191
     192  >>> os.listdir(uploadpath)
     193  ['myfaculties.csv']
     194
     195Clean up:
     196
     197  >>> import os
     198  >>> import shutil
     199  >>> shutil.rmtree(uploadpath)
Note: See TracChangeset for help on using the changeset viewer.