source: main/waeup.kofa/trunk/src/waeup/sirp/browser/browser.txt @ 7807

Last change on this file since 7807 was 7707, checked in by Henrik Bettermann, 13 years ago

Translation of browser and university package completed (hopefully).

File size: 41.9 KB
Line 
1Browsing SIRP
2*************
3
4Here we visit all parts of a SIRP portal using a browser.
5
6University
7==========
8
9We can watch universities in the browser.
10
11We create an university object and put into the ZODB root::
12
13  >>> root = getRootFolder()
14  >>> list(root)
15  []
16
17  >>> from waeup.sirp.app import University
18  >>> u = University()
19  >>> root['myuniversity'] = u
20  >>> list(root)
21  [u'myuniversity']
22
23  >>> from zope.component.hooks import setSite
24  >>> setSite(root['myuniversity'])
25
26To make sure, we can 'watch' pages, we first have to initialize out
27test browser::
28
29  >>> from zope.testbrowser.testing import Browser
30  >>> browser = Browser()
31
32Let's get the default view of a university::
33
34  >>> browser.open('http://localhost/myuniversity')
35  >>> print browser.contents
36  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
37  ...Welcome to WAeUP.SIRP...
38  ...
39
40We can change to German::
41  >>> browser.getLink('de').click()
42  >>> print browser.contents
43  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
44  ...Anfragen...
45  ...
46
47And then change back to English by clicking on the third link containing 'en'
48behind 'Anfragen' and 'Einloggen'::
49  >>> browser.getLink('en', index=2).click()
50  >>> print browser.contents
51  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
52  ...Enquiries...
53  ...
54
55The contact form for anonymous users is called 'Enquiries'::
56
57  >>> browser.open('http://localhost/myuniversity')
58  >>> browser.getLink('Enquiries').click()
59  >>> browser.getControl('Send').click()
60  >>> print browser.contents
61  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
62  ...Required input is missing...
63  ...
64
65  >>> browser.getControl(name='form.fullname').value = "Bob Tester"
66  >>> browser.getControl(name='form.email_from').value = "xx@yy.zz"
67  >>> browser.getControl(name='form.body').value = u'test message'
68  >>> browser.getControl('Send').click()
69  >>> print browser.contents
70  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
71  ...Your message has been sent...
72  ...
73
74Now we login as manager::
75
76  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
77  >>> browser.handleErrors = False
78
79We can then get an edit view of the configuration container::
80
81  >>> browser.open('http://localhost/myuniversity/configuration')
82  >>> print browser.contents
83  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
84  ...<form action="http://localhost/myuniversity/configuration/@@index"
85  ...
86
87The edit form contains the default value for the university name::
88
89  >>> 'Sample University' in browser.contents
90  True
91
92The edit form contains the default value for the portal skin::
93
94  >>> 'waeup-base.css' in browser.contents
95  True
96
97We can perform several actions on the edit form::
98
99  >>> browser.getControl("Save", index=0).click()
100  >>> print browser.contents
101  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
102  ...Settings have been saved...
103  ...
104
105  >>> browser.open('http://localhost/myuniversity/configuration')
106  >>> browser.getControl("Update plugins").click()
107  >>> print browser.contents
108  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
109  ...Plugins were updated. See log file for details...
110  ...
111
112The default frontpage ReST has been saved in a dictionary
113and is properly rendered on the frontpage of the portal:
114
115  >>> browser.open('http://localhost/myuniversity')
116  >>> print browser.contents
117  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
118  ...<h1>Welcome to the Student Information and Registration Portal...</h1>
119  ...
120
121The German part is really not being rendered:
122
123  >>> 'Willkommen' in browser.contents
124  False
125
126
127If we change to German so that the German part of frontpage.rst is rendered:
128
129  >>> browser.open('http://localhost/myuniversity//@@change_language?lang=de')
130  >>> print browser.contents
131  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
132  ...<h1>Willkommen im Studenteninformations- und Registrierungsportal</h1>
133  ...
134
135The English part is really not being rendered:
136
137  >>> 'Welcome' in browser.contents
138  False
139
140Switch back to English:
141
142  >>> browser.open('http://localhost/myuniversity//@@change_language?lang=en')
143
144We can export a university as XML::
145
146  >>> browser.open('http://localhost/myuniversity/export.xml')
147  >>> print browser.contents
148  <?xml version="1.0" encoding="utf-8" ?>
149  <pickle>
150  ...
151  </pickle>
152
153  >>> print browser.headers
154  Status: 200 Ok
155  Content-Length: ...
156  Content-Type: text/xml; charset=UTF-8
157  X-Powered-By: Zope (www.zope.org), Python (www.python.org)
158
159
160Portal Users
161============
162
163  >>> browser.open('http://localhost/myuniversity')
164  >>> browser.getLink('Portal Users').click()
165  >>> print browser.contents
166  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
167  ...Portal Users...
168  ...
169
170We can add users:
171
172  >>> browser.getLink("Add user").click()
173  >>> browser.getControl(name="form.name").value = 'bob'
174  >>> browser.getControl(name="password").value = 'secret'
175  >>> browser.getControl(name="control_password").value = 'secret'
176  >>> browser.getControl(name="form.email").value = 'xx@yy.zz'
177  >>> browser.getControl(name="form.phone").value = '1234'
178  >>> browser.getControl("Add user").click()
179  >>> print browser.contents
180  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
181  ...<td>bob</td>
182  ...
183
184We can edit user bob:
185
186  >>> browser.getControl("Manage", index=0).click()
187  >>> browser.getControl("Save", index=0).click()
188  >>> browser.getControl("Cancel", index=0).click()
189
190We can add site roles which are then displayed on the user container page.
191Since the test browser does not use javascript, we have to add site roles
192manually by setting the roles attribute:
193
194  >>> print root['myuniversity']['users']['bob'].roles
195  []
196  >>> root['myuniversity']['users']['bob'].roles = ['waeup.ApplicationsOfficer']
197  >>> print root['myuniversity']['users']['bob'].roles
198  ['waeup.ApplicationsOfficer']
199  >>> browser.open('http://localhost/myuniversity/users')
200  >>> print browser.contents
201  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
202  ...<td>Applications Officer <br /></td>
203  ...
204
205Users can't be added twice:
206
207  >>> browser.open('http://localhost/myuniversity/users/add')
208  >>> browser.getControl(name="form.name").value = 'bob'
209  >>> browser.getControl(name="password").value = 'secret'
210  >>> browser.getControl(name="control_password").value = 'secret'
211  >>> browser.getControl(name="form.email").value = 'xx@yy.zz'
212  >>> browser.getControl(name="form.phone").value = '1234'
213  >>> browser.getControl("Add user").click()
214  >>> 'The userid chosen already exists' in browser.contents
215  True
216
217Users can be deleted:
218
219  >>> browser.open('http://localhost/myuniversity/users')
220  >>> browser.getControl("Remove").click()
221  >>> 'User account bob successfully deleted' in browser.contents
222  True
223
224
225Contact Form
226============
227
228Let's enter the contact form::
229
230  >>> browser.open('http://localhost/myuniversity/contactadmin')
231  >>> print browser.contents
232  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
233  ...Contact
234  ...
235
236We fill the form  (this will send a real message to
237contact@waeup.org)::
238
239  >>> browser.open('http://localhost/myuniversity/contactadmin')
240  >>> browser.getControl(name='form.body').value = "test message"
241  >>> browser.getControl('Send').click()
242  >>> print browser.contents
243  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
244  ...Your message has been sent...
245  ...
246
247If this test fails, chances are, that the local machine has no SMTP
248server installed.
249
250
251
252Faculties
253=========
254
255Faculties are stored in a special container of `IUniversity`
256instances. The container is called ``faculties`` and provides an
257add-form to add new faculties::
258
259  >>> browser.open('http://localhost/myuniversity/faculties/manage')
260  >>> browser.getControl('Add faculty').click()
261  >>> print browser.contents
262  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
263  ...*...
264  ...<span>Name of faculty</span>:
265  ...
266  >>> browser.getControl('Cancel').click()
267  >>> browser.open('http://localhost/myuniversity/faculties/add')
268
269We fill in a new name for our new faculty::
270
271  >>> ctrl = browser.getControl(name='form.title')
272  >>> ctrl.value = 'TestFac'
273
274Furthermore we add a prefix and a code (kind of abbreviation):
275
276  >>> browser.getControl(name='form.code').value = 'TF'
277
278Finally we click on 'Add Faculty' to add the new thing::
279
280  >>> browser.getControl('Add faculty').click()
281
282We can view a faculty by browsing a URL like this::
283
284  >>> browser.open('http://localhost/myuniversity/faculties/TF')
285
286Afterwards, the faculty should be visible:
287
288  >>> browser.open('http://localhost/myuniversity/faculties')
289  >>> print browser.contents
290  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
291  ...<h1>Academic Section</h1>
292  ...<td> <a href="TF"> <span>TF</span></a></td>
293  ...
294
295We can 'visit' each faculty by clicking on the appropriate link:
296
297  >>> browser.getLink('TF').click()
298  >>> print browser.contents
299  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
300  ...Faculty of TestFac (TF)...
301  ...
302
303If we add the same faculty twice, an error message will occur:
304
305  >>> browser.open('http://localhost/myuniversity/faculties/add')
306  >>> ctrl = browser.getControl(name='form.title')
307  >>> ctrl.value = 'TestFac'
308  >>> browser.getControl(name='form.code').value = 'TF'
309  >>> browser.getControl('Add faculty').click()
310  >>> 'The faculty code chosen already exists.' in browser.contents
311  True
312
313Modifying faculties
314-------------------
315
316A faculty can directly be reached by its code:
317
318  >>> browser.open('http://localhost/myuniversity/faculties/TF')
319
320We can change the settings for a faculty by clicking on the
321provided 'Manage  faculty' button:
322
323  >>> browser.getLink('Manage faculty').click()
324
325Let's set a new title and save the form:
326
327  >>> browser.getControl(name='form.title').value = "My renamed faculty"
328  >>> browser.getControl(name='form.actions.save').click()
329
330Our faculty was indeed renamed to ``My renamed faculty``:
331
332  >>> browser.open('http://localhost/myuniversity/faculties')
333  >>> print browser.contents
334  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
335  ...<h1>Academic Section</h1>
336  ...<td> <a href="TF"> <span>TF</span></a></td>
337  ...<td>Faculty of My renamed faculty (TF)</td>
338  ...
339
340We can grant local roles:
341
342  >>> root['myuniversity']['users'].addUser('bob', 'secret',title='Bob',
343  ...                               description='A sample user')
344  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
345  >>> browser.getControl(name="user").value = ['bob']
346  >>> browser.getControl(
347  ...     name="local_role").value = ['waeup.local.DepartmentManager']
348  >>> browser.getControl("Add local role").click()
349  >>> print browser.contents
350  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
351  ...<td>bob</td>
352  ...
353
354On the portal user page the new local role is displayed:
355
356  >>> browser.getLink("Portal Users").click()
357  >>> print browser.contents
358  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
359  ...<td>Department Manager:...
360  ...
361
362The local role can be removed again:
363
364  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
365  >>> ctrl = browser.getControl(name='role_id')
366  >>> browser.getControl("Remove selected local roles").click()
367  >>> print browser.contents
368  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
369  ...No local role selected...
370  ...
371
372  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
373  >>> ctrl = browser.getControl(name='role_id')
374  >>> ctrl.getControl(value='bob|waeup.local.DepartmentManager').selected = True
375  >>> browser.getControl("Remove selected local roles").click()
376  >>> print browser.contents
377  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
378  ...Local role successfully removed...
379  ...
380
381Deleting faculties
382------------------
383
384  >>> browser.open('http://localhost/myuniversity/faculties/manage')
385  >>> browser.getControl('Cancel').click()
386  >>> print browser.url
387  http://localhost/myuniversity/faculties
388  >>> browser.getLink('Manage academic section').click()
389  >>> browser.getControl('Add faculty').click()
390  >>> ctrl = browser.getControl(name='form.title')
391  >>> ctrl.value = 'Second Faculty'
392  >>> browser.getControl(name='form.code').value = 'TF2'
393  >>> browser.getControl('Add faculty').click()
394  >>> browser.open('http://localhost/myuniversity/faculties/manage')
395  >>> browser.getControl("Remove selected", index=0).click()
396  >>> 'No item selected' in browser.contents
397  True
398  >>> browser.open('http://localhost/myuniversity/faculties/manage')
399  >>> ctrl = browser.getControl(name='val_id')
400  >>> ctrl.getControl(value='TF2').selected = True
401  >>> browser.getControl("Remove selected", index=0).click()
402  >>> print browser.contents
403  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
404  ...Successfully removed:...
405  ...
406
407Departments
408===========
409
410Adding departments
411------------------
412
413Departments are stored in :class:`IFaculty` instances with their code
414as key. Faculties therefore are also department containers. Faculties
415provides an add-form to add new departments:
416
417  >>> browser.open('http://localhost/myuniversity/faculties/TF/add')
418  >>> print browser.contents
419  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
420  ...*</span>
421  ...<span>Name of department</span>:
422  ...
423  >>> browser.getControl('Cancel').click()
424  >>> browser.open('http://localhost/myuniversity/faculties/TF/add')
425
426We fill in a new name for our new department:
427
428  >>> ctrl = browser.getControl(name='form.title')
429  >>> ctrl.value = 'TestDept'
430
431Furthermore we add a code (kind of abbreviation):
432
433  >>> browser.getControl(name='form.code').value = 'TD'
434
435Finally we click on 'Add Department' to add the new thing::
436
437  >>> browser.getControl('Add department').click()
438
439If we try to register a department under the same code twice we will
440get an error:
441
442  >>> browser.open('http://localhost/myuniversity/faculties/TF/add')
443  >>> ctrl = browser.getControl(name='form.title')
444  >>> ctrl.value = 'Another TestDept with same code'
445  >>> browser.getControl(name='form.code').value = 'TD'
446  >>> browser.getControl('Add department').click()
447  >>> print browser.contents
448  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
449  ...The code chosen already exists in this faculty...
450  ...
451
452We can view a department by browsing a URL like this::
453
454  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
455
456Afterwards, the department should be visible::
457
458  >>> browser.open('http://localhost/myuniversity/faculties/TF')
459  >>> print browser.contents
460  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
461  ...<h1>Departments</h1>
462  ...<td> <a href="TD"> <span>TD</span></a></td>
463  ...<td>Department of TestDept (TD)</td>
464  ...
465
466
467Modifying departments
468---------------------
469
470We can change the settings for a department by clicking on the
471provided 'Edit department' button:
472
473  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
474  >>> browser.getLink('Manage department').click()
475
476Let's set a new title and save the form:
477
478  >>> browser.getControl(name='form.title').value = "My test dept"
479  >>> browser.getControl(name='form.actions.save').click()
480
481Clicking 'Save' we will stay on the settings form. So we can change
482the department again.
483
484  >>> browser.getControl(name='form.title').value = "My renamed dept"
485  >>> ctrl = browser.getControl("Save")
486  >>> ctrl.click()
487
488
489Our department was indeed renamed to ``My renamed dept``:
490
491  >>> browser.open('http://localhost/myuniversity/faculties/TF')
492  >>> print browser.contents
493  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
494  ...<h1>Departments</h1>
495  ...<td> <a href="TD"> <span>TD</span></a></td>
496  ...<td>Department of My renamed dept (TD)</td>
497  ...
498
499We can grant local roles:
500
501  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/manage')
502  >>> browser.getControl(name="user").value = ['bob']
503  >>> browser.getControl(
504  ...     name="local_role").value = ['waeup.local.DepartmentManager']
505  >>> browser.getControl("Add local role").click()
506  >>> print browser.contents
507  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
508  ...<td>bob</td>
509  ...
510
511The local role can be removed again:
512
513  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/manage')
514  >>> ctrl = browser.getControl(name='role_id')
515  >>> browser.getControl("Remove selected local roles").click()
516  >>> print browser.contents
517  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
518  ...No local role selected...
519  ...
520
521  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/manage')
522  >>> ctrl = browser.getControl(name='role_id')
523  >>> ctrl.getControl(
524  ...     value='bob|waeup.local.DepartmentManager').selected = True
525  >>> browser.getControl("Remove selected local roles").click()
526  >>> print browser.contents
527  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
528  ...Local role successfully removed...
529  ...
530
531Deleting departments
532--------------------
533
534  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
535  >>> browser.getControl('Cancel', index=0).click()
536  >>> print browser.url
537  http://localhost/myuniversity/faculties/TF
538  >>> browser.getLink('Manage faculty').click()
539  >>> browser.getControl('Add department').click()
540  >>> ctrl = browser.getControl(name='form.title')
541  >>> ctrl.value = 'Second Department'
542  >>> browser.getControl(name='form.code').value = 'TD2'
543  >>> browser.getControl('Add department').click()
544  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
545  >>> browser.getControl("Remove selected", index=0).click()
546  >>> 'No item selected' in browser.contents
547  True
548  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
549  >>> ctrl = browser.getControl(name='val_id')
550  >>> ctrl.getControl(value='TD2').selected = True
551  >>> browser.getControl("Remove selected", index=0).click()
552  >>> print browser.contents
553  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
554  ...Successfully removed:...
555  ...
556
557
558Courses
559=======
560
561Once we have a department, we can add courses.
562
563Adding courses
564--------------
565
566Courses are stored in :class:`ICoursesContainer` instances with their
567code as key. CoursesContainers are normally availabe as `course`
568attribute of :class:`waeup.sirp.university.department.Department`
569instances.
570
571To ease the life of users we do not require to browse the
572coursescontainers (which have a rather flat user interface), but
573provide adding of courses in department views.
574
575Each department provides a ``Add course`` action button near top.
576
577Departments provide an add-form to add new courses:
578
579  >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD'
580  >>> browser.open(dept_url + '/manage')
581  >>> browser.getControl('Add course').click()
582  >>> print browser.contents
583  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
584  ...*</span>
585  ...<span>Title of course</span>:
586  ...
587
588We fill in a name for our new course:
589
590  >>> ctrl = browser.getControl(name='form.title')
591  >>> ctrl.value = 'My Course 1'
592
593Furthermore we add a code (kind of abbreviation):
594
595  >>> browser.getControl(name='form.code').value = 'COURSE1'
596
597This course will take place in the the first semester, so we set the
598`semester` value to 1:
599
600  >>> ctrl = browser.getControl(name='form.semester')
601  >>> ctrl.options
602  ['1', '2', '3', '9']
603
604  >>> ctrl.displayOptions
605  ['First Semester', 'Second Semester', 'Combined', 'N/A']
606
607  >>> ctrl.value = ['1']
608
609Finally, we create the course:
610
611  >>> browser.getControl('Add course').click()
612
613If we try to register a course under the same code twice we will
614get an error:
615
616  >>> browser.open(dept_url + '/addcourse')
617  >>> ctrl = browser.getControl(name='form.title')
618  >>> ctrl.value = 'Another course with same code'
619  >>> browser.getControl(name='form.code').value = 'COURSE1'
620  >>> browser.getControl('Add course').click()
621  >>> print browser.contents
622  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
623  ...A course with same code already exists:...
624  ...
625
626Our course will be linked under the code on the department page:
627
628  >>> browser.open(dept_url)
629  >>> browser.getLink('COURSE1').click()
630  >>> browser.url
631  'http://localhost/myuniversity/faculties/TF/TD/courses/COURSE1'
632
633Before we really add a course we can cancel the action and will be
634redirected to the department page:
635
636  >>> browser.open(dept_url + '/addcourse')
637  >>> browser.getControl('Cancel').click()
638  >>> browser.url
639  'http://localhost/myuniversity/faculties/TF/TD'
640
641
642Modifying courses
643-----------------
644
645We can change the settings for a course by clicking on the provided
646'Edit settings' link:
647
648  >>> browser.open(dept_url + '/courses/COURSE1')
649  >>> browser.getLink('Edit course').click()
650
651When modifying a course, we cannot change the code any more:
652
653  >>> browser.getControl(name='form.code')
654  Traceback (most recent call last):
655  ...
656  LookupError: name 'form.code'
657
658Let's set a new title and save the form:
659
660  >>> browser.getControl(name='form.title').value = "My test course"
661  >>> browser.getControl(name='form.actions.save').click()
662
663Clicking 'Save' we will stay on the settings form. So we can change
664the course again. If we click ``Cancel`` nothing will be
665changed:
666
667  >>> browser.getControl(name='form.title').value = "Blah"
668  >>> browser.getControl('Cancel').click()
669
670Our course was not renamed to ``Blah``:
671
672  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
673  >>> print browser.contents
674  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
675  ...<td>My test course</td>...
676  ...
677
678Searching courses
679-----------------
680
681  >>> browser.open('http://localhost/myuniversity/faculties/search')
682  >>> browser.getControl(name='query').value = "My test course"
683  >>> browser.getControl('Search').click()
684  >>> print browser.contents
685  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
686  ...faculties/TF/TD/courses/COURSE1">COURSE1</a>
687  ...
688
689  >>> browser.open('http://localhost/myuniversity/faculties/search')
690  >>> browser.getControl(name='query').value = "COURSE1"
691  >>> browser.getControl('Search').click()
692  >>> print browser.contents
693  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
694  ...faculties/TF/TD/courses/COURSE1">COURSE1</a>
695  ...
696
697  >>> browser.getControl(name='query').value = "Nonsense"
698  >>> browser.getControl('Search').click()
699  >>> 'Search Results' in browser.contents
700  False
701
702  >>> browser.getControl(name='query').value = ""
703  >>> browser.getControl('Search').click()
704  >>> 'Empty search string' in browser.contents
705  True
706
707Deleting courses
708----------------
709
710We can delete courses by browsing the manage page of the containing
711department and checking the appropriate select box and clicking the
712´´Remove selected´´ button.
713
714  >>> browser.open(
715  ...     'http://localhost/myuniversity/faculties/TF/TD/@@manage#tab-2')
716  >>> 'My test course' in browser.contents
717  True
718
719  >>> browser.getControl('Cancel', index=0).click()
720  >>> browser.getLink('Manage department').click()
721  >>> browser.getControl('Remove selected courses').click()
722  >>> 'No item selected' in browser.contents
723  True
724
725  >>> browser.getControl(
726  ...    name='val_id').getControl(value='COURSE1').selected = True
727  >>> browser.getControl('Remove selected courses').click()
728
729  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
730  >>> 'My renamed course' in browser.contents
731  False
732
733
734Deleting departments with courses
735---------------------------------
736
737  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
738  >>> browser.getControl('Cancel', index=0).click()
739  >>> browser.getLink('Manage faculty').click()
740  >>> browser.getControl('Add department').click()
741  >>> ctrl = browser.getControl(name='form.title')
742  >>> ctrl.value = 'Third Department'
743  >>> browser.getControl(name='form.code').value = 'TD3'
744  >>> browser.getControl('Add department').click()
745  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD3/manage')
746  >>> browser.getControl('Add course').click()
747  >>> ctrl = browser.getControl(name='form.title')
748  >>> ctrl.value = 'My Course 5'
749  >>> browser.getControl(name='form.code').value = 'COURSE5'
750  >>> browser.getControl('Add course').click()
751  >>> browser.open('http://localhost/myuniversity/faculties/TF/manage')
752  >>> ctrl = browser.getControl(name='val_id')
753  >>> ctrl.getControl(value='TD3').selected = True
754  >>> browser.getControl("Remove selected", index=0).click()
755  >>> print browser.contents
756  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
757  ...Successfully removed:...
758  ...
759
760Certificates
761============
762
763Once we have a department, we can add also certificats.
764
765Adding certificates
766-------------------
767
768Certificates are stored in :class:`ICertificatesContainer` instances
769with their code as key. CertificatesContainers are normally availabe as
770`certificates` attribute of
771:class:`waeup.sirp.university.department.Department` instances.
772
773To ease the life of users we do not require to browse the
774certificatescontainers (which have in fact no user interface), but
775provide adding of certificates in department views.
776
777Each department provides a ``Add certificate`` action button near top.
778
779Departments provide an add-form to add new certificates:
780
781  >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD'
782  >>> browser.open(dept_url + '/manage')
783  >>> browser.getControl('Add certificate').click()
784  >>> print browser.contents
785  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
786  ...*</span>
787  ...<span>Title</span>:
788  ...
789
790We fill in a name for our new cert:
791
792  >>> ctrl = browser.getControl(name='form.title')
793  >>> ctrl.value = 'My Certificate 1'
794
795Furthermore we add a code (kind of abbreviation):
796
797  >>> browser.getControl(name='form.code').value = 'CERT1'
798
799Set the remaining required fields:
800
801  >>> browser.getControl(name='form.study_mode').value = ['ume_ft']
802  >>> browser.getControl(name='form.start_level').value = ['100']
803  >>> browser.getControl(name='form.end_level').value = ['400']
804  >>> browser.getControl(name='form.application_category').value = ['basic']
805
806Finally, we create the certificate:
807
808  >>> browser.getControl('Add certificate').click()
809
810If we try to register a certificate under the same code twice we will
811get an error:
812
813  >>> browser.open(dept_url + '/addcertificate')
814  >>> ctrl = browser.getControl(name='form.title')
815  >>> ctrl.value = 'Another cert with same code'
816  >>> browser.getControl(name='form.code').value = 'CERT1'
817  >>> browser.getControl(name='form.study_mode').value = ['ume_ft']
818  >>> browser.getControl(name='form.start_level').value = ['100']
819  >>> browser.getControl(name='form.end_level').value = ['400']
820  >>> browser.getControl(name='form.application_category').value = ['basic']
821
822  >>> browser.getControl('Add certificate').click()
823  >>> print browser.contents
824  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
825  ...A certificate with same code already exists:...
826  ...
827
828Our certificate will be linked under the code on the department page:
829
830  >>> browser.open(dept_url)
831  >>> browser.getLink('CERT1').click()
832  >>> browser.url
833  'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1'
834
835Before we really add a certificate we can cancel the action and will be
836redirected to the department page:
837
838  >>> browser.open(dept_url + '/addcertificate')
839  >>> browser.getControl('Cancel').click()
840  >>> browser.url
841  'http://localhost/myuniversity/faculties/TF/TD'
842
843
844Modifying certificates
845----------------------
846
847We can change the settings for a cert by clicking on the provided
848'Edit certificate' link:
849
850  >>> browser.open(dept_url + '/certificates/CERT1')
851  >>> browser.getLink('Manage certificate').click()
852
853When modifying a certificate, we cannot change the code any more:
854
855  >>> browser.getControl(name='form.code')
856  Traceback (most recent call last):
857  ...
858  LookupError: name 'form.code'
859
860Let's set a new title and save the form:
861
862  >>> browser.getControl(name='form.title').value = "My test cert"
863  >>> browser.getControl(name='form.actions.save').click()
864
865Clicking 'Save' we will stay on the settings form. So we can change
866the cert again.
867
868  >>> browser.getControl(name='form.title').value = "My renamed cert"
869  >>> ctrl = browser.getControl("Save",index=0)
870  >>> ctrl.click()
871
872If we go to the settings page and click ``Cancel`` nothing will be
873changed:
874
875  >>> browser.getControl(name='form.title').value = "Blah"
876  >>> browser.getControl('Cancel',index=0).click()
877
878Our certificate was indeed renamed to ``My renamed cert`` and not to
879``Blah``:
880
881  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
882  >>> print browser.contents
883  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
884  ...<td>My renamed cert</td>...
885  ...
886
887Searching certificates
888----------------------
889
890  >>> browser.open('http://localhost/myuniversity/faculties/search')
891  >>> browser.getControl(name='query').value = "My renamed cert"
892  >>> browser.getControl('Search').click()
893  >>> print browser.contents
894  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
895  ...faculties/TF/TD/certificates/CERT1">CERT1</a>
896  ...
897
898  >>> browser.open('http://localhost/myuniversity/faculties/search')
899  >>> browser.getControl(name='query').value = "CERT1"
900  >>> browser.getControl('Search').click()
901  >>> print browser.contents
902  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
903  ...faculties/TF/TD/certificates/CERT1">CERT1</a>
904  ...
905
906Deleting certificates
907---------------------
908
909We can delete certificates by browsing the manage page of the
910containing department and checking the appropriate select box and
911clicking the ´´Remove selected´´ button.
912
913  >>> browser.open(
914  ...    'http://localhost/myuniversity/faculties/TF/TD/@@manage#tab-3')
915  >>> 'My renamed cert' in browser.contents
916  True
917
918  >>> browser.getControl('Remove selected certificates').click()
919  >>> 'No item selected' in browser.contents
920  True
921
922  >>> browser.getControl(name='val_id').getControl(
923  ...    value='CERT1').selected = True
924  >>> browser.getControl('Remove selected certificates').click()
925  >>> 'My renamed cert' in browser.contents
926  False
927
928
929CertificateCourses
930==================
931
932Once we have a certificate, we can add also certificate courses. These
933are referrers of courses with some extra data.
934
935Before we can work with certificate courses, we need some certificates
936and courses to be available.
937
938  >>> browser.open(dept_url + '/addcourse')
939  >>> ctrl = browser.getControl(name='form.title')
940  >>> ctrl.value = 'Another course with same code'
941  >>> browser.getControl(name='form.code').value = 'COURSE1'
942  >>> browser.getControl(name='form.title').value = 'Course 1'
943  >>> browser.getControl('Add course').click()
944
945  >>> browser.open(dept_url + '/addcourse')
946  >>> ctrl = browser.getControl(name='form.title')
947  >>> ctrl.value = 'Another course with same code'
948  >>> browser.getControl(name='form.code').value = 'COURSE2'
949  >>> browser.getControl(name='form.title').value = 'Course 2'
950  >>> browser.getControl('Add course').click()
951
952  >>> browser.open(dept_url + '/addcertificate')
953  >>> ctrl = browser.getControl(name='form.title')
954  >>> ctrl.value = 'Another cert with same code'
955  >>> browser.getControl(name='form.code').value = 'CERT1'
956  >>> browser.getControl(name='form.title').value = 'Certificate 1'
957  >>> browser.getControl(name='form.study_mode').value = ['ume_ft']
958  >>> browser.getControl(name='form.start_level').value = ['100']
959  >>> browser.getControl(name='form.end_level').value = ['400']
960  >>> browser.getControl(name='form.application_category').value = ['basic']
961  >>> browser.getControl('Add certificate').click()
962
963  >>> browser.open(dept_url + '/addcertificate')
964  >>> ctrl = browser.getControl(name='form.title')
965  >>> ctrl.value = 'Another cert with same code'
966  >>> browser.getControl(name='form.code').value = 'CERT2'
967  >>> browser.getControl(name='form.title').value = 'Certificate 2'
968  >>> browser.getControl(name='form.study_mode').value = ['ume_ft']
969  >>> browser.getControl(name='form.start_level').value = ['100']
970  >>> browser.getControl(name='form.end_level').value = ['400']
971  >>> browser.getControl(name='form.application_category').value = ['basic']
972  >>> browser.getControl('Add certificate').click()
973
974
975Adding certificatecourses
976-------------------------
977
978Certcourses are stored in :class:`ICertificate` instances
979with their code as key.
980
981Each certificate provides a ``Add course referrer`` action button near top.
982
983Certificates provide an add-form to add new certcourses:
984
985  >>> cert_url = dept_url + '/certificates/CERT1'
986  >>> browser.open(cert_url + '/manage')
987  >>> browser.getControl('Add course referrer').click()
988  >>> print browser.contents
989  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
990  ...*</span>
991  ...<span>Level</span>:
992  ...
993
994In the add-form we will get a list of available courses to select
995from. This list will contain all courses stored in the site, not only
996the ones from local department:
997
998  >>> ctrl = browser.getControl(name='form.course')
999  >>> ctrl.displayOptions
1000  ['(no value)', 'COURSE1 - Course 1', 'COURSE2 - Course 2']
1001
1002We select the first course and create our certificatecourse:
1003
1004  >>> ctrl.getControl('COURSE1').selected = True
1005  >>> browser.getControl(name='form.level').value = ['100']
1006  >>> browser.getControl('Add course referrer').click()
1007
1008Our certificatecourse will be linked on the parent certificate page:
1009
1010  >>> browser.open(cert_url)
1011  >>> browser.getLink('COURSE1_100').click()
1012  >>> browser.url
1013  'http://localhost/my...sity/faculties/TF/TD/certificates/CERT1/COURSE1_100'
1014
1015We can't add the same certificatecourse twice:
1016
1017  >>> cert_url = dept_url + '/certificates/CERT1'
1018  >>> browser.open(cert_url + '/manage')
1019  >>> browser.getControl('Add course referrer').click()
1020  >>> ctrl = browser.getControl(name='form.course')
1021  >>> ctrl.getControl('COURSE1').selected = True
1022  >>> browser.getControl(name='form.level').value = ['100']
1023  >>> browser.getControl('Add course referrer').click()
1024  >>> 'The chosen course referrer is already' in browser.contents
1025  True
1026
1027When we started to add a new certificatecourse, we can also cancel the
1028process before submitting. This will bring us back to the certificate
1029page:
1030
1031  >>> browser.open(cert_url + '/addcertificatecourse')
1032  >>> browser.getControl('Cancel').click()
1033  >>> browser.url
1034  'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1'
1035
1036
1037Modifying certificatecourses
1038----------------------------
1039
1040We can change the settings for a certcourse by clicking on the
1041provided 'Edit certificate course' link:
1042
1043  >>> browser.open(cert_url + '/COURSE1_100')
1044  >>> browser.getLink('Edit course referrer').click()
1045
1046If we just click 'Save and return' nothing will change:
1047
1048  >>> browser.getControl("Save and return").click()
1049  >>> browser.getLink('COURSE1_100').click()
1050  >>> browser.url
1051  'http://localhost/myun.../TF/TD/certificates/CERT1/COURSE1_100'
1052
1053Let's set a new level (it was 100 before) and save the form. This will
1054bring us to the certificate index page afterwards:
1055
1056  >>> browser.open(cert_url + '/COURSE1_100/manage')
1057  >>> browser.getControl(name='form.level').value = ['200']
1058  >>> browser.getControl("Save and return").click()
1059
1060As we changed the level, also the URL will change:
1061
1062  >>> browser.getLink('COURSE1_200').click()
1063  >>> browser.url
1064  'http://localhost/myun.../TF/TD/certificates/CERT1/COURSE1_200'
1065
1066If we go to the settings page and click ``Cancel`` nothing will be
1067changed:
1068
1069  >>> browser.getLink('Edit course referrer').click()
1070  >>> browser.getControl(name='form.level').value = ['400']
1071  >>> browser.getControl('Cancel').click()
1072
1073Our certcourse provides a new level of 200 and not 400:
1074
1075  >>> browser.open(cert_url + '/COURSE1_200')
1076  >>> print browser.contents
1077  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1078  ...<td>Level:</td>
1079  ...<td>200 (Year 2)</td>
1080  ...
1081
1082Searching certificatecourses
1083----------------------------
1084
1085  >>> browser.open('http://localhost/myuniversity/faculties/search')
1086  >>> browser.getControl(name='query').value = "COURSE1"
1087  >>> browser.getControl('Search').click()
1088  >>> print browser.contents
1089  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
1090  ...faculties/TF/TD/certificates/CERT1/COURSE1_200">COURSE1</a>
1091  ...
1092
1093  >>> browser.getControl(name='query').value = "*"
1094  >>> browser.getControl('Search').click()
1095  >>> 'Search string not allowed' in browser.contents
1096  True
1097
1098Deleting certificatecourses
1099---------------------------
1100
1101We can delete certcourses by browsing the containing certificate manage page:
1102
1103  >>> browser.open(cert_url + '/manage#tab-2')
1104  >>> 'COURSE1_200</a>' in browser.contents
1105  True
1106  >>> browser.getControl('Remove selected course referrers').click()
1107  >>> 'No item selected' in browser.contents
1108  True
1109  >>> browser.getControl(name='val_id').getControl(
1110  ...    value='COURSE1_200').selected = True
1111  >>> browser.getControl('Remove selected course referrers').click()
1112  >>> 'Successfully removed: COURSE1_200' in browser.contents
1113  True
1114
1115  >>> 'COURSE1_200</a>' in browser.contents
1116  False
1117
1118
1119
1120Data Center
1121===========
1122
1123The data center helps us uploading files for later import or similar.
1124
1125  >>> browser.open('http://localhost/myuniversity')
1126  >>> browser.getLink('Data Center').click()
1127
1128Setting the file path
1129---------------------
1130
1131A datacenter stores files in a path in filesystem. By default this is
1132a directory in the sources:
1133
1134  >>> print browser.contents
1135  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1136  ...
1137  <b>Storage path:</b> <span>.../parts/test/datacenter</span>
1138  ...
1139
1140Going to 'Settings` we can change the path:
1141
1142  >>> browser.getLink('Edit settings').click()
1143  >>> pathsetting = browser.getControl(name='newpath')
1144
1145We create a directory and set it as our upload path:
1146
1147  >>> import os
1148  >>> cwd = os.getcwd()
1149  >>> uploadpath = os.path.join(cwd, 'testfiles')
1150  >>> os.mkdir(uploadpath)
1151  >>> pathsetting.value = uploadpath
1152
1153And submit the form:
1154
1155  >>> browser.getControl(name='save').click()
1156
1157We clean up the set directory path, as there might be some files be
1158copied some files from installation:
1159
1160  >>> files = os.listdir(uploadpath)
1161  >>> for filename in files:
1162  ...   if os.path.isdir(os.path.join(uploadpath, filename)):
1163  ...     continue
1164  ...   os.unlink(os.path.join(uploadpath, filename))
1165
1166We also remove any existing 'accesscodes' subdir:
1167
1168  >>> import shutil
1169  >>> for filename in files:
1170  ...   if not os.path.isdir(os.path.join(uploadpath, filename)):
1171  ...     continue
1172  ...   if filename != 'accesscodes':
1173  ...     continue
1174  ...   shutil.rmtree(os.path.join(uploadpath, filename))
1175
1176The new upload directory is now empty, except from the logs and other
1177standard dirs, which are created automatically:
1178
1179  >>> sorted(os.listdir(uploadpath))
1180  ['finished', 'logs', 'unfinished']
1181
1182
1183Uploading files
1184---------------
1185
1186Now we can upload files. Most interesting files might be CSV files,
1187that can be imported lateron. We create a CSV file containing faculty
1188descriptions:
1189
1190  >>> open('faculties.csv', 'wb').write(
1191  ... """code,title,title_prefix
1192  ... FA,Arts,faculty
1193  ... FS,Sciences,faculty
1194  ... """)
1195
1196Now we can upload this file. To do this, we first go to the upload
1197page:
1198
1199  >>> browser.getLink('Upload CSV file').click()
1200
1201and enter the appropriate data in the form:
1202
1203  >>> filewidget = browser.getControl(name='uploadfile:file')
1204  >>> filewidget
1205  <Control name='uploadfile:file' type='file'>
1206
1207A sidenote for developers: by marking the filewidget with the
1208``:file`` extension, we tell Zope to handle this field as a file
1209widget.
1210
1211  >>> import cStringIO
1212  >>> filecontents = cStringIO.StringIO(
1213  ...   open('faculties.csv', 'rb').read())
1214  >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv')
1215
1216  >>> browser.getControl(name='SUBMIT').click()
1217
1218The file was indeed uploaded, with the current userid inserted:
1219
1220  >>> sorted(os.listdir(uploadpath))
1221  ['finished', 'logs', 'myfaculties_zope.mgr.csv', 'unfinished']
1222
1223We create and upload also a CSV file containing departments:
1224
1225  >>> open('departments.csv', 'wb').write(
1226  ... """code,title,title_prefix,faculty_code
1227  ... LIT,Literature,department,FA
1228  ... SOC,Sociology,department,FA
1229  ... PHY,Physics,department,FS
1230  ... INF,Informatics,department,FS
1231  ... MAT,Math,department,FS
1232  ... """)
1233
1234  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
1235  >>> browser.getControl(name='uploadfile:file').add_file(
1236  ...   cStringIO.StringIO(open('departments.csv', 'rb').read()),
1237  ...   'text/plain', 'mydepartments.csv')
1238  >>> browser.getControl(name='SUBMIT').click()
1239
1240We create and upload also a CSV file containing courses:
1241
1242  >>> open('courses.csv', 'wb').write(
1243  ... """code,level,title,passmark,credits,semester,faculty,department
1244  ... LI1,,Introduction to Literature I,40,2,1,FA,LIT
1245  ... LI2,,Introduction to Literature II,40,2,2,FA,LIT
1246  ... AN1,000,Analysis I,40,2,1,FS,MAT
1247  ... AN2,000,Analysis II,40,2,2,FS,MAT
1248  ... """)
1249
1250  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
1251  >>> browser.getControl(name='uploadfile:file').add_file(
1252  ...   cStringIO.StringIO(open('courses.csv', 'rb').read()),
1253  ...   'text/plain', 'mycourses.csv')
1254  >>> browser.getControl(name='SUBMIT').click()
1255
1256We create and upload also a CSV file containing certificates:
1257
1258  >>> open('certificates.csv', 'wb').write(
1259  ... """code,title,faculty_code,department_code,study_mode,end_level,m_prefix,start_level,application_category
1260  ... LBA,BACHELOR OF LITERATURE,FA,LIT,UG,ug_ft,500,LIT,100,basic
1261  ... LMA,MASTER OF LITERATURE,FA,LIT,UG,ug_pt,500,LIT,100,cest
1262  ... DME,DIPLOMA OF MATH,FS,MAT,DP,dp_ft,200,DME,100,cest
1263  ... """)
1264
1265  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
1266  >>> browser.getControl(name='uploadfile:file').add_file(
1267  ...   cStringIO.StringIO(open('certificates.csv', 'rb').read()),
1268  ...   'text/plain', 'mycertificates.csv')
1269  >>> browser.getControl(name='SUBMIT').click()
1270
1271We create and upload also a CSV file containing certificate courses:
1272
1273  >>> open('certcourses.csv', 'wb').write(
1274  ... """code,faculty_code,department_code,certificate_code,level,mandatory
1275  ... LI1,FA,LIT,LBA,100,True
1276  ... LI2,FA,LIT,LBA,200,True
1277  ... """)
1278
1279  >>> browser.open('http://localhost/myuniversity/datacenter/upload')
1280  >>> browser.getControl(name='uploadfile:file').add_file(
1281  ...   cStringIO.StringIO(open('certcourses.csv', 'rb').read()),
1282  ...   'text/plain', 'mycertcourses.csv')
1283  >>> browser.getControl(name='SUBMIT').click()
1284
1285
1286Importing a CSV file
1287--------------------
1288
1289The import of CSV files is described in batchprocessing.txt.
1290
1291
1292Clean up:
1293
1294  >>> import os
1295  >>> import shutil
1296  >>> shutil.rmtree(uploadpath)
1297
Note: See TracBrowser for help on using the repository browser.