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

Last change on this file since 4915 was 4905, checked in by uli, 15 years ago

Update tests.

  • Property svn:eol-style set to native
File size: 30.2 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.max_pass').value = '400'
449
450Finally, we create the certificate:
451
452  >>> browser.getControl('Add certificate').click()
453
454If we try to register a certificate under the same code twice we will
455get an error:
456
457  >>> browser.open(dept_url + '/addcertificate')
458  >>> ctrl = browser.getControl(name='form.title')
459  >>> ctrl.value = 'Another cert with same code'
460  >>> browser.getControl(name='form.code').value = 'CERT1'
461  >>> browser.getControl(name='form.category').value = 'UME'
462  >>> browser.getControl(name='form.study_mode').value = 'combined'
463  >>> browser.getControl(name='form.start_level').value = '100'
464  >>> browser.getControl(name='form.end_level').value = '400'
465  >>> browser.getControl(name='form.application_category').value = 'UME'
466  >>> browser.getControl(name='form.max_pass').value = '400'
467
468  >>> browser.getControl('Add certificate').click()
469  >>> print browser.contents
470  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
471  ...<div>The name chosen already exists in the database</div>
472  ...
473
474Our certificate will be linked under the code on the department page:
475
476  >>> browser.open(dept_url)
477  >>> browser.getLink('CERT1').click()
478  >>> browser.url
479  'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1'
480
481Before we really add a certificate we can cancel the action and will be
482redirected to the department page:
483
484  >>> browser.open(dept_url + '/addcertificate')
485  >>> browser.getControl('Cancel').click()
486  >>> browser.url
487  'http://localhost/myuniversity/faculties/TF/TD'
488
489
490Modifying certificates
491----------------------
492
493We can change the settings for a cert by clicking on the provided
494'Edit settings' link:
495
496  >>> browser.open(dept_url + '/certificates/CERT1')
497  >>> browser.getLink('Edit settings').click()
498
499When modifying a certificate, we cannot change the code any more:
500
501  >>> browser.getControl(name='form.code')
502  Traceback (most recent call last):
503  ...
504  LookupError: name 'form.code'
505
506Let's set a new title and save the form:
507
508  >>> browser.getControl(name='form.title').value = "My test cert"
509  >>> browser.getControl(name='form.actions.save').click()
510
511Clicking 'Save' we will stay on the settings form. So we can change
512the cert again. This time we will return to the overview page
513afterwards:
514
515  >>> browser.getControl(name='form.title').value = "My renamed cert"
516  >>> ctrl = browser.getControl("Save and return")
517  >>> ctrl.click()
518
519If we go to the settings page and click ``Cancel`` nothing will be
520changed:
521
522  >>> browser.getLink('Edit settings').click()
523  >>> browser.getControl(name='form.title').value = "Blah"
524  >>> browser.getControl('Cancel').click()
525
526Our certificate was indeed renamed to ``My renamed cert`` and not to
527``Blah``:
528
529  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
530  >>> print browser.contents
531  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
532  ...<div name="thecerttable">
533  ...<td>My renamed cert</td>...
534  ...
535
536
537Deleting certificates
538---------------------
539
540We can delete certificates by browsing the containing department and
541clicking on the appropriate 'Delete' button. As we have only one
542certificate, there is only one 'Delete' button yet:
543
544  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
545  >>> 'My renamed cert' in browser.contents
546  True
547
548  >>> browser.getControl('Delete').click()
549
550  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
551  >>> 'My renamed cert' in browser.contents
552  False
553
554
555CertificateCourses
556==================
557
558Once we have a certificate, we can add also certificate courses. These
559are references to courses with some extra data.
560
561Before we can work with certificate courses, we need some certificates
562and courses to be available.
563
564  >>> browser.open(dept_url + '/addcourse')
565  >>> ctrl = browser.getControl(name='form.title')
566  >>> ctrl.value = 'Another course with same code'
567  >>> browser.getControl(name='form.code').value = 'COURSE1'
568  >>> browser.getControl(name='form.title').value = 'Course 1' 
569  >>> browser.getControl('Add course').click()
570
571  >>> browser.open(dept_url + '/addcourse')
572  >>> ctrl = browser.getControl(name='form.title')
573  >>> ctrl.value = 'Another course with same code'
574  >>> browser.getControl(name='form.code').value = 'COURSE2'
575  >>> browser.getControl(name='form.title').value = 'Course 2'
576  >>> browser.getControl('Add course').click()
577
578  >>> browser.open(dept_url + '/addcertificate')
579  >>> ctrl = browser.getControl(name='form.title')
580  >>> ctrl.value = 'Another cert with same code'
581  >>> browser.getControl(name='form.code').value = 'CERT1'
582  >>> browser.getControl(name='form.title').value = 'Certificate 1'
583  >>> browser.getControl(name='form.category').value = 'UME'
584  >>> browser.getControl(name='form.study_mode').value = 'combined'
585  >>> browser.getControl(name='form.start_level').value = '100'
586  >>> browser.getControl(name='form.end_level').value = '400'
587  >>> browser.getControl(name='form.application_category').value = 'UME'
588  >>> browser.getControl(name='form.max_pass').value = '400'
589  >>> browser.getControl('Add certificate').click()
590
591  >>> browser.open(dept_url + '/addcertificate')
592  >>> ctrl = browser.getControl(name='form.title')
593  >>> ctrl.value = 'Another cert with same code'
594  >>> browser.getControl(name='form.code').value = 'CERT2'
595  >>> browser.getControl(name='form.title').value = 'Certificate 2'
596  >>> browser.getControl(name='form.category').value = 'UME'
597  >>> browser.getControl(name='form.study_mode').value = 'combined'
598  >>> browser.getControl(name='form.start_level').value = '100'
599  >>> browser.getControl(name='form.end_level').value = '400'
600  >>> browser.getControl(name='form.application_category').value = 'UME'
601  >>> browser.getControl(name='form.max_pass').value = '400'
602  >>> browser.getControl('Add certificate').click()
603 
604
605Adding certificatecourses
606-------------------------
607
608Certcourses are stored in :class:`ICertificate` instances
609with their code as key.
610
611Each certificate provides a ``Add course`` action button near top.
612
613Certificates provide an add-form to add new certcourses:
614
615  >>> cert_url = dept_url + '/certificates/CERT1'
616  >>> browser.open(cert_url + '/addcertificatecourse')
617  >>> print browser.contents
618  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
619  ...<span class="required">*</span><span>Level of this course</span>
620  ...
621
622In the add-form we will get a list of available courses to select
623from. This list will contain all courses stored in the site, not only
624the ones from local department:
625
626  >>> ctrl = browser.getControl(name='form.course')
627  >>> ctrl.displayOptions
628  ['COURSE1 Course 1', 'COURSE2 Course 2']
629
630If we do not select anything else, the first item will be
631selected. That's okay for us. Finally, we create the
632certificatecourse:
633
634  >>> browser.getControl('Add course').click()
635
636Our certificatecourse will be linked on the parent certificate page:
637
638  >>> browser.open(cert_url)
639  >>> browser.getLink('COURSE1').click()
640  >>> browser.url
641  'http://localhost/my...sity/faculties/TF/TD/certificates/CERT1/COURSE1_100'
642
643When we started to add a new certificatecourse, we can also cancel the
644process before submitting. This will bring us back to the certificate
645page:
646
647  >>> browser.open(cert_url + '/addcertificatecourse')
648  >>> browser.getControl('Cancel').click()
649  >>> browser.url
650  'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1'
651
652
653Modifying certificatecourses
654----------------------------
655
656We can change the settings for a certcourse by clicking on the
657provided 'Edit settings' link:
658
659  >>> browser.open(cert_url + '/COURSE1_100')
660  >>> browser.getLink('Edit settings').click()
661
662Let's set a new level (it was 100 before) and save the form. This will
663bring us to the certificate index page afterwards:
664
665  >>> browser.getControl(name='form.level').value = "200"
666  >>> ctrl = browser.getControl("Save and return")
667  >>> ctrl.click()
668
669As we changed the level, also the URL will change:
670
671  >>> browser.getLink('COURSE1').click()
672  >>> browser.url
673  'http://localhost/myun.../TF/TD/certificates/CERT1/COURSE1_200'
674
675If we go to the settings page and click ``Cancel`` nothing will be
676changed:
677
678  >>> browser.getLink('Edit settings').click()
679  >>> browser.getControl(name='form.level').value = "666"
680  >>> browser.getControl('Cancel').click()
681
682Our certcourse provides a new level of 200 and not 666:
683
684  >>> browser.open(cert_url + '/COURSE1_200')
685  >>> print browser.contents
686  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
687  ...Level of this course
688  ...200...
689  ...
690
691
692Deleting certificatecourses
693---------------------------
694
695We can delete certcourses by browsing the containing certificate and
696clicking on the appropriate 'Delete' button. As we have only one
697certcourse, there is only one 'Delete' button yet:
698
699  >>> browser.open(cert_url)
700  >>> 'COURSE1_200' in browser.contents
701  True
702
703  >>> browser.getControl('delete').click()
704
705  >>> browser.open(cert_url)
706  >>> 'COURSE1_200' in browser.contents
707  False
708
709
710Data Center
711===========
712
713The data center helps us uploading files for later import or similar.
714
715  >>> browser.open('http://localhost/myuniversity')
716  >>> browser.getLink('Data Center').click()
717
718Setting the file path
719---------------------
720
721A datacenter stores files in a path in filesystem. By default this is
722a directory in the sources:
723
724  >>> print browser.contents
725  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
726  ...
727  <b>Storage path:</b> <span>/.../waeup/files</span>
728  ...
729
730Going to 'Settings` we can change the path:
731
732  >>> browser.getLink('Edit settings').click()
733  >>> pathsetting = browser.getControl(name='newpath')
734
735We create a directory and set it as our upload path:
736
737  >>> import os
738  >>> cwd = os.getcwd()
739  >>> uploadpath = os.path.join(cwd, 'testfiles')
740  >>> os.mkdir(uploadpath)
741  >>> pathsetting.value = uploadpath
742
743And submit the form:
744
745  >>> browser.getControl(name='save').click()
746
747We clean up the set directory path, as there might be some files be
748copied some files from installation:
749
750  >>> files = os.listdir(uploadpath)
751  >>> for filename in files:
752  ...   if os.path.isdir(os.path.join(uploadpath, filename)):
753  ...     continue
754  ...   os.unlink(os.path.join(uploadpath, filename))
755
756The new upload directory is now empty, except from the logs and other
757standard dirs, which are created automatically:
758
759  >>> sorted(os.listdir(uploadpath))
760  ['finished', 'logs', 'unfinished']
761
762
763Uploading files
764---------------
765
766Now we can upload files. Most interesting files might be CSV files,
767that can be imported lateron. We create a CSV file containing faculty
768descriptions:
769
770  >>> open('faculties.csv', 'wb').write(
771  ... """code,title,title_prefix
772  ... FA,Arts,Faculty
773  ... FS,Sciences,Faculty
774  ... """)
775
776Now we can upload this file. To do this, we first go to the upload
777page:
778
779  >>> browser.getLink('Upload data').click()
780
781and enter the appropriate data in the form:
782
783  >>> filewidget = browser.getControl(name='uploadfile:file')
784  >>> filewidget
785  <Control name='uploadfile:file' type='file'>
786 
787A sidenote for developers: by marking the filewidget with the
788``:file`` extension, we tell Zope to handle this field as a file
789widget.
790
791  >>> import cStringIO
792  >>> filecontents = cStringIO.StringIO(
793  ...   open('faculties.csv', 'rb').read())
794  >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv')
795 
796  >>> browser.getControl(name='SUBMIT').click()
797
798The file was indeed uploaded, with the current userid inserted:
799
800  >>> sorted(os.listdir(uploadpath))
801  ['finished', 'logs', 'myfaculties_zope.mgr.csv', 'unfinished']
802
803We create and upload also a CSV file containing departments:
804
805  >>> open('departments.csv', 'wb').write(
806  ... """code,title,title_prefix,faculty_code
807  ... LIT,Literature,Department,FA
808  ... SOC,Sociology,Department,FA
809  ... PHY,Physics,Department,FS
810  ... INF,Informatics,Department,FS
811  ... MAT,Math,Department,FS
812  ... """)
813
814  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
815  >>> browser.getControl(name='uploadfile:file').add_file(
816  ...   cStringIO.StringIO(open('departments.csv', 'rb').read()),
817  ...   'text/plain', 'mydepartments.csv')
818  >>> browser.getControl(name='SUBMIT').click()
819
820We create and upload also a CSV file containing courses:
821
822  >>> open('courses.csv', 'wb').write(
823  ... """code,level,title,passmark,credits,semester,faculty,department
824  ... LI1,,Introduction to Literature I,40,2,1,FA,LIT
825  ... LI2,,Introduction to Literature II,40,2,2,FA,LIT
826  ... AN1,000,Analysis I,40,2,1,FS,MAT
827  ... AN2,000,Analysis II,40,2,2,FS,MAT
828  ... """)
829
830  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
831  >>> browser.getControl(name='uploadfile:file').add_file(
832  ...   cStringIO.StringIO(open('courses.csv', 'rb').read()),
833  ...   'text/plain', 'mycourses.csv')
834  >>> browser.getControl(name='SUBMIT').click()
835
836We create and upload also a CSV file containing certificates:
837
838  >>> open('certificates.csv', 'wb').write(
839  ... """code,title,faculty_code,department_code,category,study_mode,end_level,m_prefix,max_pass,start_level,application_category,review_state
840  ... LBA,BACHELOR OF LITERATURE,FA,LIT,UG,ug_ft,500,LIT,30,100,basic,checked
841  ... LMA,MASTER OF LITERATURE,FA,LIT,UG,ug_pt,500,LIT,30,100,cest,checked
842  ... DME,DIPLOMA OF MATH,FS,MAT,DP,dp_ft,200,DME,30,100,cest,unchecked
843  ... """)
844
845  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
846  >>> browser.getControl(name='uploadfile:file').add_file(
847  ...   cStringIO.StringIO(open('certificates.csv', 'rb').read()),
848  ...   'text/plain', 'mycertificates.csv')
849  >>> browser.getControl(name='SUBMIT').click()
850
851We create and upload also a CSV file containing certificate courses:
852
853  >>> open('certcourses.csv', 'wb').write(
854  ... """code,faculty_code,department_code,certificate_code,level,core_or_elective
855  ... LI1,FA,LIT,LBA,100,True
856  ... LI2,FA,LIT,LBA,200,True
857  ... """)
858
859  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
860  >>> browser.getControl(name='uploadfile:file').add_file(
861  ...   cStringIO.StringIO(open('certcourses.csv', 'rb').read()),
862  ...   'text/plain', 'mycertcourses.csv')
863  >>> browser.getControl(name='SUBMIT').click()
864
865
866Importing a CSV file
867--------------------
868
869As the uploaded file conforms with what we expect from a faculty-CSV
870file, we can import it. To do this we click the ``Import CSV data``
871link:
872
873  >>> browser.open('http://localhost/myuniversity/datacenter')
874  >>> browser.getLink('Import CSV data').click()
875
876Here we get all importable files listed:
877
878  >>> print browser.contents
879  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
880  ...The following files are available for import:...
881  ...mycertcourses_zope.mgr.csv...Certificate Course Importer...
882  ...mycertificates_zope.mgr.csv...Certificate Importer...
883  ...mycourses_zope.mgr.csv...Course Importer...
884  ...mydepartments_zope.mgr.csv...Department Importer...
885  ...myfaculties_zope.mgr.csv...Faculty Importer...
886  ...
887
888As we can see, the files are analyzed on-the-fly so the system can
889tell us what kind of importer is available for each.
890
891We do import the faculty file by clicking on ``Import!`` next to the
892appropriate file:
893
894  >>> facimport = browser.getControl('Import!', index=4)
895  >>> facimport.click()
896
897  >>> print browser.contents
898  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
899  ...Successfully imported: myfaculties_zope.mgr.csv...
900  ...
901
902We just created two new faculties:
903
904  >>> browser.open('http://localhost/myuniversity/faculties/')
905  >>> print browser.contents
906  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
907  ...<h2>Registered Faculties</h2>...
908  ...Arts...
909  ...Sciences...
910  ...
911
912We can also import the department data:
913
914  >>> browser.open('http://localhost/myuniversity/datacenter')
915  >>> browser.getLink('Import CSV data').click()
916  >>> browser.getControl('Import!', index=3).click()
917
918  >>> print browser.contents
919  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
920  ...Successfully imported: mydepartments_zope.mgr.csv...
921  ...
922
923We can also import the course data:
924
925  >>> browser.open('http://localhost/myuniversity/datacenter')
926  >>> browser.getLink('Import CSV data').click()
927  >>> browser.getControl('Import!', index=2).click()
928
929  >>> print browser.contents
930  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
931  ...Successfully imported: mycourses_zope.mgr.csv...
932  ...
933
934We can also import the certificate data:
935
936  >>> browser.open('http://localhost/myuniversity/datacenter')
937  >>> browser.getLink('Import CSV data').click()
938  >>> browser.getControl('Import!', index=1).click()
939
940  >>> print browser.contents
941  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
942  ...Successfully imported: mycertificates_zope.mgr.csv...
943  ...
944
945We can also import certificate courses:
946
947  >>> browser.open('http://localhost/myuniversity/datacenter')
948  >>> browser.getLink('Import CSV data').click()
949  >>> browser.getControl('Import!', index=0).click()
950
951  >>> print browser.contents
952  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
953  ...Successfully imported: mycertcourses_zope.mgr.csv...
954  ...
955
956Clean up:
957
958  >>> import os
959  >>> import shutil
960  >>> shutil.rmtree(uploadpath)
Note: See TracBrowser for help on using the repository browser.