Browsing Ikoba ************* Here we visit all parts of a Ikoba portal using a browser. Company ======= We can watch universities in the browser. We create an company object and put into the ZODB root:: >>> root = getRootFolder() >>> list(root) [] >>> from waeup.ikoba.app import Company >>> u = Company() >>> root['mycompany'] = u >>> list(root) [u'mycompany'] >>> from zope.component.hooks import setSite >>> setSite(root['mycompany']) To make sure, we can 'watch' pages, we first have to initialize out test browser:: >>> from zope.testbrowser.testing import Browser >>> browser = Browser() Let's get the default view of a company:: >>> browser.open('http://localhost/mycompany') >>> print browser.contents >> browser.getLink('de').click() >>> print browser.contents >> browser.getLink('en', index=2).click() >>> print browser.contents >> browser.open('http://localhost/mycompany') >>> browser.getLink('Enquiries').click() >>> browser.getControl('Send').click() >>> print browser.contents >> browser.getControl(name='form.fullname').value = "Bob Tester" >>> browser.getControl(name='form.email_from').value = "xx@yy.zz" >>> browser.getControl(name='form.body').value = u'test message' >>> browser.getControl('Send').click() >>> print browser.contents >> root['mycompany']['users'].addUser('forgetful', 'secret',title='Bob Forgetful', ... description='A forgetful user', email='aa@aa.ng') >>> browser.open('http://localhost/mycompany/changepw') >>> browser.getControl(name="form.email").value = 'aa@aa.ng' >>> browser.getControl("Send login credentials").click() >>> print browser.contents >> browser.addHeader('Authorization', 'Basic mgr:mgrpw') >>> browser.handleErrors = False We can then get an edit view of the configuration container:: >>> browser.open('http://localhost/mycompany/configuration') >>> print browser.contents >> 'Sample Company' in browser.contents True We can perform several actions on the edit form:: >>> browser.getControl("Save", index=0).click() >>> print browser.contents >> browser.open('http://localhost/mycompany/configuration') >>> browser.getControl("Update plugins").click() >>> print browser.contents >> browser.open('http://localhost/mycompany') >>> print browser.contents Welcome to WAeUP.Ikoba... ... The German part is really not being rendered: >>> 'Willkommen' in browser.contents False If we change to German so that the German part of frontpage.rst is rendered: >>> browser.open('http://localhost/mycompany//@@change_language?lang=de') >>> print browser.contents Willkommen auf WAeUP.Ikoba... ... The English part is really not being rendered: >>> 'Welcome' in browser.contents False Switch back to English: >>> browser.open('http://localhost/mycompany//@@change_language?lang=en') Officers ======== >>> browser.open('http://localhost/mycompany') >>> browser.getLink('Officers').click() >>> print browser.contents >> browser.getLink("Add user").click() >>> browser.getControl(name="form.name").value = 'bob' >>> browser.getControl(name="form.title").value = 'Bob The User' >>> browser.getControl(name="password").value = 'secret' >>> browser.getControl(name="control_password").value = 'secret' >>> browser.getControl(name="form.email").value = 'xx@yy.zz' >>> browser.getControl(name="form.phone.country").value = ['+234'] >>> browser.getControl(name="form.phone.area").value = '123' >>> browser.getControl(name="form.phone.ext").value = '45678' >>> browser.getControl("Add user").click() >>> print browser.contents bob ... We can edit user bob: >>> browser.getControl("Manage", index=0).click() >>> browser.getControl("Save", index=0).click() >>> browser.getControl("Cancel", index=0).click() We can add site roles which are then displayed on the user container page. Since the test browser does not use javascript, we have to add site roles manually by setting the roles attribute: Since JS is not supported by the test browser, the default role has been removed when clicking the Save button. >>> print root['mycompany']['users']['bob'].roles [] >>> root['mycompany']['users']['bob'].roles = ['waeup.UsersManager'] >>> print root['mycompany']['users']['bob'].roles ['waeup.UsersManager'] >>> browser.open('http://localhost/mycompany/users') >>> print browser.contents Users Manager
... Users can't be added twice: >>> browser.open('http://localhost/mycompany/users/add') >>> browser.getControl(name="form.name").value = 'bob' >>> browser.getControl(name="form.title").value = 'Bob The User' >>> browser.getControl(name="password").value = 'secret' >>> browser.getControl(name="control_password").value = 'secret' >>> browser.getControl(name="form.email").value = 'xx@yy.zz' >>> browser.getControl(name="form.phone.country").value = ['+234'] >>> browser.getControl(name="form.phone.area").value = '123' >>> browser.getControl(name="form.phone.ext").value = '45678' >>> browser.getControl("Add user").click() >>> 'The userid chosen already exists' in browser.contents True Users can be deleted: >>> browser.open('http://localhost/mycompany/users') >>> browser.getControl("Remove", index=0).click() >>> 'User account bob successfully deleted' in browser.contents True Contact Form ============ Let's enter the contact form:: >>> browser.open('http://localhost/mycompany/contactadmin') >>> print browser.contents >> browser.open('http://localhost/mycompany/contactadmin') >>> browser.getControl(name='form.body').value = "test message" >>> browser.getControl('Send').click() >>> print browser.contents >> browser.open('http://localhost/mycompany') >>> browser.getLink('Data Center').click() Setting the file path --------------------- A datacenter stores files in a path in filesystem. By default this is a directory in the sources: >>> print browser.contents Storage path: .../parts/test/datacenter ... Going to 'Settings` we can change the path: >>> browser.getLink('Edit settings').click() >>> pathsetting = browser.getControl(name='newpath') We create a directory and set it as our upload path: >>> import os >>> cwd = os.getcwd() >>> uploadpath = os.path.join(cwd, 'testfiles') >>> os.mkdir(uploadpath) >>> pathsetting.value = uploadpath And submit the form: >>> browser.getControl(name='save').click() We clean up the set directory path, as there might be some files be copied some files from installation: >>> files = os.listdir(uploadpath) >>> for filename in files: ... if os.path.isdir(os.path.join(uploadpath, filename)): ... continue ... os.unlink(os.path.join(uploadpath, filename)) We also remove any existing 'accesscodes' subdir: >>> import shutil >>> for filename in files: ... if not os.path.isdir(os.path.join(uploadpath, filename)): ... continue ... if filename != 'accesscodes': ... continue ... shutil.rmtree(os.path.join(uploadpath, filename)) The new upload directory is now empty, except from the logs and other standard dirs, which are created automatically: >>> sorted(os.listdir(uploadpath)) ['deleted', 'finished', 'logs', 'unfinished'] Uploading files --------------- Now we can upload files. Most interesting files might be CSV files, that can be imported lateron. We create a CSV file containing faculty descriptions: >>> open('faculties.csv', 'wb').write( ... """code,title,title_prefix ... FA,Arts,faculty ... FS,Sciences,faculty ... """) Now we can upload this file. To do this, we first go to the upload page: >>> browser.getLink('Upload data').click() and enter the appropriate data in the form: >>> filewidget = browser.getControl(name='uploadfile:file') >>> filewidget A sidenote for developers: by marking the filewidget with the ``:file`` extension, we tell Zope to handle this field as a file widget. >>> import cStringIO >>> filecontents = cStringIO.StringIO( ... open('faculties.csv', 'rb').read()) >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv') >>> browser.getControl(name='SUBMIT').click() The file was indeed uploaded, with the current userid inserted: >>> sorted(os.listdir(uploadpath)) ['deleted', 'finished', 'logs', 'myfaculties_zope.mgr.csv', 'unfinished'] Importing a CSV file -------------------- The import of CSV files is described in batchprocessing.txt. Clean up: >>> import os >>> import shutil >>> shutil.rmtree(uploadpath)