source: waeup/branches/ulif-namespace/src/sirp/browser.txt @ 4792

Last change on this file since 4792 was 4789, checked in by uli, 15 years ago

Merge changes from ulif-layout back into trunk (finally).

  • Property svn:eol-style set to native
File size: 30.1 KB
Line 
1Browsing the WAeUP portal
2*************************
3
4Here we visit all parts of a WAeUP portal using a browser.
5
6:Test-Layer: functional
7
8University
9==========
10
11We can watch universities in the browser.
12
13To make sure, we can 'watch' pages, we first have to initialize out
14test browser::
15
16  >>> from zope.testbrowser.testing import Browser
17  >>> browser = Browser()
18  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
19  >>> browser.handleErrors = False
20
21We create an university object and put into the ZODB root::
22
23  >>> root = getRootFolder()
24  >>> list(root)
25  []
26
27  >>> from waeup.app import University
28  >>> u = University()
29  >>> root['myuniversity'] = u
30  >>> list(root)
31  [u'myuniversity']
32
33
34Let's get the default view of a university::
35
36  >>> browser.open('http://localhost/myuniversity')
37  >>> print browser.contents
38  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
39  ...Welcome to the...
40  ...
41
42We can also get an edit view of a university::
43
44  >>> browser.open('http://localhost/myuniversity/manage')
45  >>> print browser.contents
46  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
47  ...<form action="http://localhost/myuniversity/manage"
48  ...
49
50The edit form contains the default value for the university name::
51
52  >>> 'Sample University' in browser.contents
53  True
54
55We can export a university as XML::
56
57  >>> browser.open('http://localhost/myuniversity/export.xml')
58  >>> print browser.contents
59  <?xml version="1.0" encoding="utf-8" ?>
60  <pickle>
61  ...
62  </pickle>
63
64  >>> print browser.headers
65  Status: 200 Ok
66  Content-Length: ...
67  Content-Type: text/xml; charset=UTF-8
68  X-Powered-By: Zope (www.zope.org), Python (www.python.org)
69
70
71Faculties
72=========
73
74Faculties are stored in a special container of `IUniversity`
75instances. The container is called ``faculties`` and provides an
76add-form to add new faculties::
77
78  >>> browser.open('http://localhost/myuniversity/faculties/add')
79  >>> print browser.contents
80  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
81  ...<span class="required">*</span><span>Name of Faculty</span>
82  ...
83
84We fill in a new name for our new faculty::
85
86  >>> ctrl = browser.getControl(name='form.title')
87  >>> ctrl.value = 'TestFac'
88
89Furthermore we add a prefix and a code (kind of abbreviation):
90
91  >>> browser.getControl(name='form.code').value = 'TF'
92
93Finally we click on 'Add Faculty' to add the new thing::
94
95  >>> browser.getControl('Add faculty').click()
96
97We can view a faculty by browsing a URL like this::
98
99  >>> browser.open('http://localhost/myuniversity/faculties/TF')
100
101Afterwards, the faculty should be visible:
102
103  >>> browser.open('http://localhost/myuniversity/faculties')
104  >>> print browser.contents
105  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
106  ...<h2>Registered Faculties</h2>
107  ...<td><a href="http://localhost/myuniversity/faculties/TF">TF</a></td><td>Faculty of TestFac</td>
108  ...
109
110We can 'visit' each faculty by clicking on the appropriate link:
111
112  >>> browser.getLink('TF').click()
113  >>> print browser.contents
114  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
115  ...<h2>Faculty of TestFac (TF)</h2>...
116  ...
117
118Modifying faculties
119-------------------
120
121A faculty can directly be reached by its code:
122
123  >>> browser.open('http://localhost/myuniversity/faculties/TF')
124
125We can change the settings for a faculty by clicking on the
126provided 'Edit  settings' button:
127
128  >>> browser.getLink('Edit settings').click()
129
130Let's set a new title and save the form:
131
132  >>> browser.getControl(name='form.title').value = "My test faculty"
133  >>> browser.getControl(name='form.actions.save').click()
134
135Clicking 'Save' we will stay on the settings form. So we can change
136the department again. This time we will return to the overview page
137afterwards:
138
139  >>> browser.getControl(name='form.title').value = "My renamed faculty"
140  >>> ctrl = browser.getControl("Save and return")
141  >>> ctrl.click()
142
143If we go to the settings page and click ``Cancel`` nothing will be
144changed:
145
146  >>> browser.getLink('Edit settings').click()
147  >>> browser.getControl(name='form.title').value = "Blah"
148  >>> browser.getControl('Cancel').click()
149
150Our faculty was indeed renamed to ``My renamed faculty`` and not to
151``Blah``:
152
153  >>> browser.open('http://localhost/myuniversity/faculties')
154  >>> print browser.contents
155  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
156  ...<h2>Registered Faculties</h2>
157  ...<td><a href="http://localhost/myuniversity/faculties/TF">TF</a></td><td>Faculty of My renamed faculty</td>
158  ...
159
160
161Departments
162===========
163
164Adding departments
165------------------
166
167Departments are stored in :class:`IFaculty` instances with their code
168as key. Faculties therefore are also department containers. Faculties
169provides an add-form to add new departments:
170
171  >>> browser.open('http://localhost/myuniversity/faculties/TF/add')
172  >>> print browser.contents
173  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
174  ...<span class="required">*</span><span>Name of Department</span>
175  ...
176
177We fill in a new name for our new department:
178
179  >>> ctrl = browser.getControl(name='form.title')
180  >>> ctrl.value = 'TestDept'
181
182Furthermore we add a code (kind of abbreviation):
183
184  >>> browser.getControl(name='form.code').value = 'TD'
185
186Finally we click on 'Add Department' to add the new thing::
187
188  >>> browser.getControl('Add department').click()
189
190If we try to register a department under the same code twice we will
191get an error:
192
193  >>> browser.open('http://localhost/myuniversity/faculties/TF/add')
194  >>> ctrl = browser.getControl(name='form.title')
195  >>> ctrl.value = 'Another TestDept with same code'
196  >>> browser.getControl(name='form.code').value = 'TD'
197  >>> browser.getControl('Add department').click()
198  >>> print browser.contents
199  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
200  ...<div>The name chosen already exists in the database</div>
201  ...
202
203We can view a department by browsing a URL like this:
204
205  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
206
207Afterwards, the department should be visible:
208
209  >>> browser.open('http://localhost/myuniversity/faculties/TF')
210  >>> print browser.contents
211  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
212  ...<h2>Registered Departments:</h2>
213  ...<td><a href="http://localhost/myuniversity/faculties/TF/TD">TD</a></td><td>Department of TestDept</td>
214  ...
215
216
217Modifying departments
218---------------------
219
220We can change the settings for a department by clicking on the
221provided 'Edit settings' button:
222
223  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
224  >>> browser.getLink('Edit settings').click()
225
226Let's set a new title and save the form:
227
228  >>> browser.getControl(name='form.title').value = "My test dept"
229  >>> browser.getControl(name='form.actions.save').click()
230
231Clicking 'Save' we will stay on the settings form. So we can change
232the department again. This time we will return to the overview page
233afterwards:
234
235  >>> browser.getControl(name='form.title').value = "My renamed dept"
236  >>> ctrl = browser.getControl("Save and return")
237  >>> ctrl.click()
238
239If we go to the settings page and click ``Cancel`` nothing will be
240changed:
241
242  >>> browser.getLink('Edit settings').click()
243  >>> browser.getControl(name='form.title').value = "Blah"
244  >>> browser.getControl('Cancel').click()
245
246Our department was indeed renamed to ``My renamed dept`` and not to
247``Blah``:
248
249  >>> browser.open('http://localhost/myuniversity/faculties/TF')
250  >>> print browser.contents
251  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
252  ...<h2>Registered Departments:</h2>
253  ...<td><a href="http://localhost/myuniversity/faculties/TF/TD">TD</a></td><td>Department of My renamed dept</td>
254  ...
255
256
257Courses
258=======
259
260Once we have a department, we can add courses.
261
262Adding courses
263--------------
264
265Courses are stored in :class:`ICourseContainer` instances with their
266code as key. CourseContainers are normally availabe as `course`
267attribute of :class:`waeup.university.department.Department`
268instances.
269
270To ease the life of users we do not require to browse the
271coursecontainers (which have a rather flat user interface), but
272provide adding of courses in department views.
273
274Each department provides a ``Add course`` action button near top.
275
276Departments provide an add-form to add new courses:
277
278  >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD'
279  >>> browser.open(dept_url + '/addcourse')
280  >>> print browser.contents
281  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
282  ...<span class="required">*</span><span>Title of course</span>
283  ...
284
285We fill in a name for our new course:
286
287  >>> ctrl = browser.getControl(name='form.title')
288  >>> ctrl.value = 'My Course 1'
289
290Furthermore we add a code (kind of abbreviation):
291
292  >>> browser.getControl(name='form.code').value = 'COURSE1'
293
294This course will take place in the the first semester, so we set the
295`semester` value to 1:
296
297  >>> ctrl = browser.getControl(name='form.semester')
298  >>> ctrl.options
299  ['0', '1', '2', '3']
300
301  >>> ctrl.displayOptions
302  ['N/A', 'First Semester', 'Second Semester', 'Combined']
303
304  >>> ctrl.value = ['1']
305
306Finally, we create the course:
307
308  >>> browser.getControl('Add course').click()
309
310If we try to register a course under the same code twice we will
311get an error:
312
313  >>> browser.open(dept_url + '/addcourse')
314  >>> ctrl = browser.getControl(name='form.title')
315  >>> ctrl.value = 'Another course with same code'
316  >>> browser.getControl(name='form.code').value = 'COURSE1'
317  >>> browser.getControl('Add course').click()
318  >>> print browser.contents
319  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
320  ...<div>The code chosen already exists in the database</div>
321  ...
322
323Our course will be linked under the code on the department page:
324
325  >>> browser.open(dept_url)
326  >>> browser.getLink('COURSE1').click()
327  >>> browser.url
328  'http://localhost/myuniversity/faculties/TF/TD/courses/COURSE1'
329
330Before we really add a course we can cancel the action and will be
331redirected to the department page:
332
333  >>> browser.open(dept_url + '/addcourse')
334  >>> browser.getControl('Cancel').click()
335  >>> browser.url
336  'http://localhost/myuniversity/faculties/TF/TD'
337
338
339Modifying courses
340-----------------
341
342We can change the settings for a course by clicking on the provided
343'Edit settings' link:
344
345  >>> browser.open(dept_url + '/courses/COURSE1')
346  >>> browser.getLink('Edit settings').click()
347
348When modifying a course, we cannot change the code any more:
349
350  >>> browser.getControl(name='form.code')
351  Traceback (most recent call last):
352  ...
353  LookupError: name 'form.code'
354
355Let's set a new title and save the form:
356
357  >>> browser.getControl(name='form.title').value = "My test course"
358  >>> browser.getControl(name='form.actions.save').click()
359
360Clicking 'Save' we will stay on the settings form. So we can change
361the course again. This time we will return to the overview page
362afterwards:
363
364  >>> browser.getControl(name='form.title').value = "My renamed course"
365  >>> ctrl = browser.getControl("Save and return")
366  >>> ctrl.click()
367
368If we go to the settings page and click ``Cancel`` nothing will be
369changed:
370
371  >>> browser.getLink('Edit settings').click()
372  >>> browser.getControl(name='form.title').value = "Blah"
373  >>> browser.getControl('Cancel').click()
374
375Our course was indeed renamed to ``My renamed course`` and not to
376``Blah``:
377
378  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
379  >>> print browser.contents
380  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
381  ...<div name="thecoursetable">
382  ...<td>My renamed course</td>...
383  ...
384
385
386Deleting courses
387----------------
388
389We can delete courses by browsing the containing department and
390clicking on the appropriate 'Delete' button. As we have only one
391course, there is only one 'Delete' button yet:
392
393  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
394  >>> 'My renamed course' in browser.contents
395  True
396
397  >>> browser.getControl('Delete').click()
398
399  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
400  >>> 'My renamed course' in browser.contents
401  False
402
403
404Certificates
405============
406
407Once we have a department, we can add also certificats.
408
409Adding certificates
410-------------------
411
412Certificates are stored in :class:`ICertificateContainer` instances
413with their code as key. CertificateContainers are normally availabe as
414`certificates` attribute of
415:class:`waeup.university.department.Department` instances.
416
417To ease the life of users we do not require to browse the
418certificatecontainers (which have in fact no user interface), but
419provide adding of certificates in department views.
420
421Each department provides a ``Add certificate`` action button near top.
422
423Departments provide an add-form to add new certificates:
424
425  >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD'
426  >>> browser.open(dept_url + '/addcertificate')
427  >>> print browser.contents
428  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
429  ...<span class="required">*</span><span>title</span>
430  ...
431
432We fill in a name for our new cert:
433
434  >>> ctrl = browser.getControl(name='form.title')
435  >>> ctrl.value = 'My Certificate 1'
436
437Furthermore we add a code (kind of abbreviation):
438
439  >>> browser.getControl(name='form.code').value = 'CERT1'
440
441Set the remaining required fields:
442
443  >>> browser.getControl(name='form.category').value = 'UME'
444  >>> browser.getControl(name='form.study_mode').value = 'combined'
445  >>> browser.getControl(name='form.start_level').value = '100'
446  >>> browser.getControl(name='form.end_level').value = '400'
447  >>> browser.getControl(name='form.application_category').value = 'UME'
448  >>> browser.getControl(name='form.m_prefix').value = 'something'
449  >>> browser.getControl(name='form.max_pass').value = '400'
450
451Finally, we create the certificate:
452
453  >>> browser.getControl('Add certificate').click()
454
455If we try to register a certificate under the same code twice we will
456get an error:
457
458  >>> browser.open(dept_url + '/addcertificate')
459  >>> ctrl = browser.getControl(name='form.title')
460  >>> ctrl.value = 'Another cert with same code'
461  >>> browser.getControl(name='form.code').value = 'CERT1'
462  >>> browser.getControl(name='form.category').value = 'UME'
463  >>> browser.getControl(name='form.study_mode').value = 'combined'
464  >>> browser.getControl(name='form.start_level').value = '100'
465  >>> browser.getControl(name='form.end_level').value = '400'
466  >>> browser.getControl(name='form.application_category').value = 'UME'
467  >>> browser.getControl(name='form.m_prefix').value = 'something'
468  >>> browser.getControl(name='form.max_pass').value = '400'
469
470  >>> browser.getControl('Add certificate').click()
471  >>> print browser.contents
472  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
473  ...<div>The name chosen already exists in the database</div>
474  ...
475
476Our certificate will be linked under the code on the department page:
477
478  >>> browser.open(dept_url)
479  >>> browser.getLink('CERT1').click()
480  >>> browser.url
481  'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1'
482
483Before we really add a certificate we can cancel the action and will be
484redirected to the department page:
485
486  >>> browser.open(dept_url + '/addcertificate')
487  >>> browser.getControl('Cancel').click()
488  >>> browser.url
489  'http://localhost/myuniversity/faculties/TF/TD'
490
491
492Modifying certificates
493----------------------
494
495We can change the settings for a cert by clicking on the provided
496'Edit settings' link:
497
498  >>> browser.open(dept_url + '/certificates/CERT1')
499  >>> browser.getLink('Edit settings').click()
500
501When modifying a certificate, we cannot change the code any more:
502
503  >>> browser.getControl(name='form.code')
504  Traceback (most recent call last):
505  ...
506  LookupError: name 'form.code'
507
508Let's set a new title and save the form:
509
510  >>> browser.getControl(name='form.title').value = "My test cert"
511  >>> browser.getControl(name='form.actions.save').click()
512
513Clicking 'Save' we will stay on the settings form. So we can change
514the cert again. This time we will return to the overview page
515afterwards:
516
517  >>> browser.getControl(name='form.title').value = "My renamed cert"
518  >>> ctrl = browser.getControl("Save and return")
519  >>> ctrl.click()
520
521If we go to the settings page and click ``Cancel`` nothing will be
522changed:
523
524  >>> browser.getLink('Edit settings').click()
525  >>> browser.getControl(name='form.title').value = "Blah"
526  >>> browser.getControl('Cancel').click()
527
528Our certificate was indeed renamed to ``My renamed cert`` and not to
529``Blah``:
530
531  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
532  >>> print browser.contents
533  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
534  ...<div name="thecerttable">
535  ...<td>My renamed cert</td>...
536  ...
537
538
539Deleting certificates
540---------------------
541
542We can delete certificates by browsing the containing department and
543clicking on the appropriate 'Delete' button. As we have only one
544certificate, there is only one 'Delete' button yet:
545
546  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
547  >>> 'My renamed cert' in browser.contents
548  True
549
550  >>> browser.getControl('Delete').click()
551
552  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
553  >>> 'My renamed cert' in browser.contents
554  False
555
556
557CertificateCourses
558==================
559
560Once we have a certificate, we can add also certificate courses. These
561are references to courses with some extra data.
562
563Before we can work with certificate courses, we need some certificates
564and courses to be available.
565
566  >>> browser.open(dept_url + '/addcourse')
567  >>> ctrl = browser.getControl(name='form.title')
568  >>> ctrl.value = 'Another course with same code'
569  >>> browser.getControl(name='form.code').value = 'COURSE1'
570  >>> browser.getControl(name='form.title').value = 'Course 1' 
571  >>> browser.getControl('Add course').click()
572
573  >>> browser.open(dept_url + '/addcourse')
574  >>> ctrl = browser.getControl(name='form.title')
575  >>> ctrl.value = 'Another course with same code'
576  >>> browser.getControl(name='form.code').value = 'COURSE2'
577  >>> browser.getControl(name='form.title').value = 'Course 2'
578  >>> browser.getControl('Add course').click()
579
580  >>> browser.open(dept_url + '/addcertificate')
581  >>> ctrl = browser.getControl(name='form.title')
582  >>> ctrl.value = 'Another cert with same code'
583  >>> browser.getControl(name='form.code').value = 'CERT1'
584  >>> browser.getControl(name='form.title').value = 'Certificate 1'
585  >>> browser.getControl(name='form.category').value = 'UME'
586  >>> browser.getControl(name='form.study_mode').value = 'combined'
587  >>> browser.getControl(name='form.start_level').value = '100'
588  >>> browser.getControl(name='form.end_level').value = '400'
589  >>> browser.getControl(name='form.application_category').value = 'UME'
590  >>> browser.getControl(name='form.m_prefix').value = 'something'
591  >>> browser.getControl(name='form.max_pass').value = '400'
592  >>> browser.getControl('Add certificate').click()
593
594  >>> browser.open(dept_url + '/addcertificate')
595  >>> ctrl = browser.getControl(name='form.title')
596  >>> ctrl.value = 'Another cert with same code'
597  >>> browser.getControl(name='form.code').value = 'CERT2'
598  >>> browser.getControl(name='form.title').value = 'Certificate 2'
599  >>> browser.getControl(name='form.category').value = 'UME'
600  >>> browser.getControl(name='form.study_mode').value = 'combined'
601  >>> browser.getControl(name='form.start_level').value = '100'
602  >>> browser.getControl(name='form.end_level').value = '400'
603  >>> browser.getControl(name='form.application_category').value = 'UME'
604  >>> browser.getControl(name='form.m_prefix').value = 'something'
605  >>> browser.getControl(name='form.max_pass').value = '400'
606  >>> browser.getControl('Add certificate').click()
607 
608
609Adding certificatecourses
610-------------------------
611
612Certcourses are stored in :class:`ICertificate` instances
613with their code as key.
614
615Each certificate provides a ``Add course`` action button near top.
616
617Certificates provide an add-form to add new certcourses:
618
619  >>> cert_url = dept_url + '/certificates/CERT1'
620  >>> browser.open(cert_url + '/addcertificatecourse')
621  >>> print browser.contents
622  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
623  ...<span class="required">*</span><span>Level of this course</span>
624  ...
625
626In the add-form we will get a list of available courses to select
627from. This list will contain all courses stored in the site, not only
628the ones from local department:
629
630  >>> ctrl = browser.getControl(name='form.course')
631  >>> ctrl.displayOptions
632  ['COURSE1 Course 1', 'COURSE2 Course 2']
633
634If we do not select anything else, the first item will be
635selected. That's okay for us. Finally, we create the
636certificatecourse:
637
638  >>> browser.getControl('Add course').click()
639
640Our certificatecourse will be linked on the parent certificate page:
641
642  >>> browser.open(cert_url)
643  >>> browser.getLink('COURSE1').click()
644  >>> browser.url
645  'http://localhost/my...sity/faculties/TF/TD/certificates/CERT1/COURSE1_100'
646
647When we started to add a new certificatecourse, we can also cancel the
648process before submitting. This will bring us back to the certificate
649page:
650
651  >>> browser.open(cert_url + '/addcertificatecourse')
652  >>> browser.getControl('Cancel').click()
653  >>> browser.url
654  'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1'
655
656
657Modifying certificatecourses
658----------------------------
659
660We can change the settings for a certcourse by clicking on the
661provided 'Edit settings' link:
662
663  >>> browser.open(cert_url + '/COURSE1_100')
664  >>> browser.getLink('Edit settings').click()
665
666Let's set a new level (it was 100 before) and save the form. This will
667bring us to the certificate index page afterwards:
668
669  >>> browser.getControl(name='form.level').value = "200"
670  >>> ctrl = browser.getControl("Save and return")
671  >>> ctrl.click()
672
673As we changed the level, also the URL will change:
674
675  >>> browser.getLink('COURSE1').click()
676  >>> browser.url
677  'http://localhost/myun.../TF/TD/certificates/CERT1/COURSE1_200'
678
679If we go to the settings page and click ``Cancel`` nothing will be
680changed:
681
682  >>> browser.getLink('Edit settings').click()
683  >>> browser.getControl(name='form.level').value = "666"
684  >>> browser.getControl('Cancel').click()
685
686Our certcourse provides a new level of 200 and not 666:
687
688  >>> browser.open(cert_url + '/COURSE1_200')
689  >>> print browser.contents
690  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
691  ...Level of this course
692  ...200...
693  ...
694
695
696Deleting certificatecourses
697---------------------------
698
699We can delete certcourses by browsing the containing certificate and
700clicking on the appropriate 'Delete' button. As we have only one
701certcourse, there is only one 'Delete' button yet:
702
703  >>> browser.open(cert_url)
704  >>> 'COURSE1_200' in browser.contents
705  True
706
707  >>> browser.getControl('delete').click()
708
709  >>> browser.open(cert_url)
710  >>> 'COURSE1_200' in browser.contents
711  False
712
713
714Data Center
715===========
716
717The data center helps us uploading files for later import or similar.
718
719  >>> browser.open('http://localhost/myuniversity')
720  >>> browser.getLink('Data Center').click()
721
722Setting the file path
723---------------------
724
725A datacenter stores files in a path in filesystem. By default this is
726a directory in the sources:
727
728  >>> print browser.contents
729  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
730  ...
731  <b>Storage path:</b> <span>/.../waeup/files</span>
732  ...
733
734Going to 'Settings` we can change the path:
735
736  >>> browser.getLink('Edit settings').click()
737  >>> pathsetting = browser.getControl(name='newpath')
738
739We create a directory and set it as our upload path:
740
741  >>> import os
742  >>> cwd = os.getcwd()
743  >>> uploadpath = os.path.join(cwd, 'testfiles')
744  >>> os.mkdir(uploadpath)
745  >>> pathsetting.value = uploadpath
746
747And submit the form:
748
749  >>> browser.getControl(name='save').click()
750
751We clean up the set directory path, as there might be some files be
752copied some files from installation:
753
754  >>> files = os.listdir(uploadpath)
755  >>> for filename in files:
756  ...   os.unlink(os.path.join(uploadpath, filename))
757
758The new upload directory is now empty:
759
760  >>> os.listdir(uploadpath)
761  []
762
763
764Uploading files
765---------------
766
767Now we can upload files. Most interesting files might be CSV files,
768that can be imported lateron. We create a CSV file containing faculty
769descriptions:
770
771  >>> open('faculties.csv', 'wb').write(
772  ... """code,title,title_prefix
773  ... FA,Arts,Faculty
774  ... FS,Sciences,Faculty
775  ... """)
776
777Now we can upload this file. To do this, we first go to the upload
778page:
779
780  >>> browser.getLink('Upload data').click()
781
782and enter the appropriate data in the form:
783
784  >>> filewidget = browser.getControl(name='uploadfile:file')
785  >>> filewidget
786  <Control name='uploadfile:file' type='file'>
787 
788A sidenote for developers: by marking the filewidget with the
789``:file`` extension, we tell Zope to handle this field as a file
790widget.
791
792  >>> import cStringIO
793  >>> filecontents = cStringIO.StringIO(
794  ...   open('faculties.csv', 'rb').read())
795  >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv')
796 
797  >>> browser.getControl(name='SUBMIT').click()
798
799The file was indeed uploaded:
800
801  >>> os.listdir(uploadpath)
802  ['myfaculties.csv']
803
804We create and upload also a CSV file containing departments:
805
806  >>> open('departments.csv', 'wb').write(
807  ... """code,title,title_prefix,faculty_code
808  ... LIT,Literature,Department,FA
809  ... SOC,Sociology,Department,FA
810  ... PHY,Physics,Department,FS
811  ... INF,Informatics,Department,FS
812  ... MAT,Math,Department,FS
813  ... """)
814
815  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
816  >>> browser.getControl(name='uploadfile:file').add_file(
817  ...   cStringIO.StringIO(open('departments.csv', 'rb').read()),
818  ...   'text/plain', 'mydepartments.csv')
819  >>> browser.getControl(name='SUBMIT').click()
820
821We create and upload also a CSV file containing courses:
822
823  >>> open('courses.csv', 'wb').write(
824  ... """code,level,title,passmark,credits,semester,faculty,department
825  ... LI1,,Introduction to Literature I,40,2,1,FA,LIT
826  ... LI2,,Introduction to Literature II,40,2,2,FA,LIT
827  ... AN1,000,Analysis I,40,2,1,FS,MAT
828  ... AN2,000,Analysis II,40,2,2,FS,MAT
829  ... """)
830
831  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
832  >>> browser.getControl(name='uploadfile:file').add_file(
833  ...   cStringIO.StringIO(open('courses.csv', 'rb').read()),
834  ...   'text/plain', 'mycourses.csv')
835  >>> browser.getControl(name='SUBMIT').click()
836
837We create and upload also a CSV file containing certificates:
838
839  >>> open('certificates.csv', 'wb').write(
840  ... """code,title,faculty_code,department_code,category,study_mode,end_level,m_prefix,max_pass,start_level,application_category,review_state
841  ... LBA,BACHELOR OF LITERATURE,FA,LIT,UG,ug_ft,500,LIT,30,100,basic,checked
842  ... LMA,MASTER OF LITERATURE,FA,LIT,UG,ug_pt,500,LIT,30,100,cest,checked
843  ... DME,DIPLOMA OF MATH,FS,MAT,DP,dp_ft,200,DME,30,100,cest,unchecked
844  ... """)
845
846  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
847  >>> browser.getControl(name='uploadfile:file').add_file(
848  ...   cStringIO.StringIO(open('certificates.csv', 'rb').read()),
849  ...   'text/plain', 'mycertificates.csv')
850  >>> browser.getControl(name='SUBMIT').click()
851
852We create and upload also a CSV file containing certificate courses:
853
854  >>> open('certcourses.csv', 'wb').write(
855  ... """code,faculty_code,department_code,certificate_code,level,core_or_elective
856  ... LI1,FA,LIT,LBA,100,True
857  ... LI2,FA,LIT,LBA,200,True
858  ... """)
859
860  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
861  >>> browser.getControl(name='uploadfile:file').add_file(
862  ...   cStringIO.StringIO(open('certcourses.csv', 'rb').read()),
863  ...   'text/plain', 'mycertcourses.csv')
864  >>> browser.getControl(name='SUBMIT').click()
865
866
867Importing a CSV file
868--------------------
869
870As the uploaded file conforms with what we expect from a faculty-CSV
871file, we can import it. To do this we click the ``Import CSV data``
872link:
873
874  >>> browser.open('http://localhost/myuniversity/datacenter')
875  >>> browser.getLink('Import CSV data').click()
876
877Here we get all importable files listed:
878
879  >>> print browser.contents
880  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
881  ...The following files are available for import:...
882  ...mycertcourses.csv...Certificate Course Importer...
883  ...mycertificates.csv...Certificate Importer...
884  ...mycourses.csv...Course Importer...
885  ...mydepartments.csv...Department Importer...
886  ...myfaculties.csv...Faculty Importer...
887  ...
888
889As we can see, the files are analyzed on-the-fly so the system can
890tell us what kind of importer is available for each.
891
892We do import the faculty file by clicking on ``Import!`` next to the
893appropriate file:
894
895  >>> facimport = browser.getControl('Import!', index=4)
896  >>> facimport.click()
897
898  >>> print browser.contents
899  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
900  ...Successfully imported: myfaculties.csv...
901  ...
902
903We just created two new faculties:
904
905  >>> browser.open('http://localhost/myuniversity/faculties/')
906  >>> print browser.contents
907  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
908  ...<h2>Registered Faculties</h2>...
909  ...Arts...
910  ...Sciences...
911  ...
912
913We can also import the department data:
914
915  >>> browser.open('http://localhost/myuniversity/datacenter')
916  >>> browser.getLink('Import CSV data').click()
917  >>> browser.getControl('Import!', index=3).click()
918
919  >>> print browser.contents
920  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
921  ...Successfully imported: mydepartments.csv...
922  ...
923
924We can also import the course data:
925
926  >>> browser.open('http://localhost/myuniversity/datacenter')
927  >>> browser.getLink('Import CSV data').click()
928  >>> browser.getControl('Import!', index=2).click()
929
930  >>> print browser.contents
931  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
932  ...Successfully imported: mycourses.csv...
933  ...
934
935We can also import the certificate data:
936
937  >>> browser.open('http://localhost/myuniversity/datacenter')
938  >>> browser.getLink('Import CSV data').click()
939  >>> browser.getControl('Import!', index=1).click()
940
941  >>> print browser.contents
942  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
943  ...Successfully imported: mycertificates.csv...
944  ...
945
946We can also import certificate courses:
947
948  >>> browser.open('http://localhost/myuniversity/datacenter')
949  >>> browser.getLink('Import CSV data').click()
950  >>> browser.getControl('Import!', index=0).click()
951
952  >>> print browser.contents
953  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
954  ...Successfully imported: mycertcourses.csv...
955  ...
956
957Clean up:
958
959  >>> import os
960  >>> import shutil
961  >>> shutil.rmtree(uploadpath)
Note: See TracBrowser for help on using the repository browser.