source: main/waeup.sirp/trunk/src/waeup/sirp/browser/batchprocessing.txt @ 7738

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

Backup translation work in progress.

File size: 16.8 KB
Line 
1Batch processing via browser
2****************************
3
4Preliminaries:
5
6We define a function that looks up a form with several submit buttons
7for the one with a given value (this functionality is missing in
8zope.testbrowser):
9
10    >>> def lookup_submit_value(name, value, browser):
11    ...   """Find a button with a certain value."""
12    ...   for num in range(0, 100):
13    ...     try:
14    ...       button = browser.getControl(name=name, index=num)
15    ...       if button.value.endswith(value):
16    ...         return button
17    ...     except IndexError:
18    ...       break
19    ...   return None
20
21Create a site:
22
23    >>> from waeup.sirp.app import University
24    >>> getRootFolder()['app'] = University()
25
26Create a datacenter storage path:
27
28    >>> import os
29    >>> import tempfile
30    >>> dc_path = tempfile.mkdtemp()
31
32Log in:
33
34    >>> from zope.testbrowser.testing import Browser
35    >>> browser = Browser()
36    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
37    >>> browser.handleErrors = False
38
39Set datacenter path and deselect moving old data:
40
41    >>> browser.open('http://localhost/app')
42    >>> browser.getLink('Data Center').click()
43    >>> browser.getLink('Edit settings').click()
44    >>> browser.getControl(name='newpath').value = dc_path
45    >>> browser.getControl(name='move').value = False
46    >>> browser.getControl(name='save').click()
47
48Set non-usable datacenter path:
49
50    >>> browser.getLink('Edit settings').click()
51    >>> browser.getControl(name='newpath').value = '/'
52    >>> browser.getControl(name='save').click()
53    >>> 'Given storage path cannot be used.' in browser.contents
54    True
55    >>> browser.getControl('Cancel').click()
56
57
58Batch processing faculties
59==========================
60
61Go to datacenter page:
62
63    >>> browser.open('http://localhost/app/datacenter')
64
65Prepare a CSV file for faculties:
66
67    >>> open('faculties.csv', 'wb').write(
68    ... """code,title,title_prefix
69    ... FAC1,Faculty 1,faculty
70    ... FAC2,Faculty 2,institute
71    ... FAC3,Faculty 3,school
72    ... """)
73
74Upload the file:
75
76    >>> import cStringIO
77    >>> browser.getLink('Upload CSV file').click()
78    >>> filecontents = cStringIO.StringIO(
79    ...   open('faculties.csv', 'rb').read())
80    >>> filewidget = browser.getControl(name='uploadfile:file')
81    >>> filewidget.add_file(filecontents, 'text/plain', 'faculties.csv')
82    >>> browser.getControl(name='SUBMIT').click()
83
84Step 1: start batch processing:
85
86    >>> browser.getLink('Batch processing').click()
87    >>> button = lookup_submit_value(
88    ...   'select', 'faculties_zope.mgr.csv', browser)
89    >>> button.click()
90
91Step 2: select a processor and mode:
92
93    >>> importerselect = browser.getControl(name='importer')
94    >>> importerselect.displayOptions
95    ['Applicant Importer',
96     'Applicants Container Importer',
97     'CourseTicket Importer',
98     'Payment Importer',
99     'Student Importer',
100     'StudentStudyCourse Importer (update only)',
101     'StudentStudyLevel Importer',
102     'CertificateCourse Importer',
103     'Certificate Importer',
104     'Course Importer',
105     'Department Importer',
106     'Faculty Importer']
107
108    >>> importerselect.getControl('Faculty Importer').selected = True
109
110    >>> modeselect = browser.getControl(name='mode')
111    >>> modeselect.options
112    ['create', 'update', 'remove']
113
114    >>> modeselect.getControl(value='create').selected = True
115    >>> browser.getControl('Proceed to step 3').click()
116
117Step 3: Fix headerlines
118
119We get informed that there are no problems with the current header:
120
121    >>> print browser.contents
122    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
123    ...
124    Header fields OK
125    ...
126
127The submit button is enabled:
128
129    >>> browser.getControl('Perform import').disabled
130    False
131
132    >>> browser.getControl('Perform import').click()
133
134Step 4: See import results
135
136The import was successful:
137
138    >>> print browser.contents
139    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
140    ...Successfully processed 3 rows...
141    ...Batch processing finished...
142    ...File:...faculties_zope.mgr.csv...
143
144We can watch the entries generated in logfile:
145
146    >>> browser.getControl('View processing log').click()
147    >>> print browser.contents
148    <!DOCTYPE ...
149    <pre>...
150 
151    ... - INFO - --------------------
152    ... - INFO - zope.mgr: Batch processing finished: OK
153    ... - INFO - zope.mgr: Source: /.../faculties_zope.mgr.csv
154    ... - INFO - zope.mgr: Mode: create
155    ... - INFO - zope.mgr: User: zope.mgr
156    ... - INFO - zope.mgr: Processing time: ... s (... s/item)
157    ... - INFO - zope.mgr: Processed: 3 lines (3 successful/ 0 failed)
158    ... - INFO - --------------------
159    </pre>
160    ....
161
162
163Batch processing departments
164============================
165
166    >>> browser.open('http://localhost/app/datacenter')
167
168Prepare a CSV file for departments:
169
170    >>> open('departments.csv', 'wb').write(
171    ... """code,faculty_code,title,title_prefix
172    ... DEP1,FAC1,Department 1,department
173    ... DEP2,FAC2,Department 2,centre
174    ... """)
175
176Upload the file:
177
178    >>> import cStringIO
179    >>> browser.getLink('Upload CSV file').click()
180    >>> filecontents = cStringIO.StringIO(
181    ...   open('departments.csv', 'rb').read())
182    >>> filewidget = browser.getControl(name='uploadfile:file')
183    >>> filewidget.add_file(filecontents, 'text/plain', 'departments.csv')
184    >>> browser.getControl(name='SUBMIT').click()
185
186Step 1: start batch processing:
187
188    >>> browser.getLink('Batch processing').click()
189    >>> button = lookup_submit_value(
190    ...   'select', 'departments_zope.mgr.csv', browser)
191    >>> button.click()
192
193Step 2: select a processor and mode:
194
195    >>> importerselect = browser.getControl(name='importer')
196    >>> importerselect.getControl('Department Importer').selected = True
197    >>> modeselect = browser.getControl(name='mode')
198    >>> modeselect.getControl(value='create').selected = True
199    >>> browser.getControl('Proceed to step 3').click()
200
201Step 3: Fix headerlines
202
203We get informed that there are no problems with the current header:
204
205    >>> print browser.contents
206    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
207    ...
208    Header fields OK
209    ...
210
211The submit button is enabled:
212
213    >>> browser.getControl('Perform import').disabled
214    False
215
216    >>> browser.getControl('Perform import').click()
217
218Step 4: See import results
219
220The import was successful:
221
222    >>> print browser.contents
223    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
224    ...Successfully processed 2 rows...
225    ...Batch processing finished...
226    ...File:...departments_zope.mgr.csv...
227
228Batch processing courses
229========================
230
231    >>> browser.open('http://localhost/app/datacenter')
232
233Prepare a CSV file for courses:
234
235    >>> open('courses.csv', 'wb').write(
236    ... """code,faculty_code,department_code,title,level,passmark,credits,semester
237    ... CRS1,FAC1,DEP1,Course 1,100,40,2,1
238    ... CRS2,FAC1,DEP1,Course 2,100,40,2,2
239    ... """)
240
241Upload the file:
242
243    >>> import cStringIO
244    >>> browser.getLink('Upload CSV file').click()
245    >>> filecontents = cStringIO.StringIO(
246    ...   open('courses.csv', 'rb').read())
247    >>> filewidget = browser.getControl(name='uploadfile:file')
248    >>> filewidget.add_file(filecontents, 'text/plain', 'courses.csv')
249    >>> browser.getControl(name='SUBMIT').click()
250
251Step 1: start batch processing:
252
253    >>> browser.getLink('Batch processing').click()
254    >>> button = lookup_submit_value(
255    ...   'select', 'courses_zope.mgr.csv', browser)
256    >>> button.click()
257
258Step 2: select a processor and mode:
259
260    >>> importerselect = browser.getControl(name='importer')
261    >>> importerselect.getControl('Course Importer', index=2).selected = True
262    >>> modeselect = browser.getControl(name='mode')
263    >>> modeselect.getControl(value='create').selected = True
264    >>> browser.getControl('Proceed to step 3').click()
265
266Step 3: Fix headerlines
267
268We get informed that there are no problems with the current header:
269
270    >>> print browser.contents
271    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
272    ...
273    Header fields OK
274    ...
275
276The submit button is enabled:
277
278    >>> browser.getControl('Perform import').disabled
279    False
280
281    >>> browser.getControl('Perform import').click()
282
283Step 4: See import results
284
285The import was successful:
286
287    >>> print browser.contents
288    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
289    ...Successfully processed 2 rows...
290    ...Batch processing finished...
291    ...File:...courses_zope.mgr.csv...
292
293Batch processing certificates
294=============================
295
296    >>> browser.open('http://localhost/app/datacenter')
297
298Prepare a CSV file for certificates:
299
300    >>> open('certificates.csv', 'wb').write(
301    ... """code,faculty_code,department_code,title,study_mode,start_level,end_level,application_category
302    ... CERT1,FAC1,DEP1,Certificate 1,ug_ft,100,300,basic
303    ... CERT2,FAC1,DEP1,Certificate 2,ug_ft,200,300,cest
304    ... """)
305
306Upload the file:
307
308    >>> import cStringIO
309    >>> browser.getLink('Upload CSV file').click()
310    >>> filecontents = cStringIO.StringIO(
311    ...   open('certificates.csv', 'rb').read())
312    >>> filewidget = browser.getControl(name='uploadfile:file')
313    >>> filewidget.add_file(filecontents, 'text/plain', 'certificates.csv')
314    >>> browser.getControl(name='SUBMIT').click()
315
316Step 1: start batch processing:
317
318    >>> browser.getLink('Batch processing').click()
319    >>> button = lookup_submit_value(
320    ...   'select', 'certificates_zope.mgr.csv', browser)
321    >>> button.click()
322
323
324Step 2: select a processor and mode:
325
326    >>> importerselect = browser.getControl(name='importer')
327    >>> importerselect.getControl('Certificate Importer').selected = True
328    >>> modeselect = browser.getControl(name='mode')
329    >>> modeselect.getControl(value='create').selected = True
330    >>> browser.getControl('Proceed to step 3').click()
331
332Step 3: Fix headerlines
333
334We get informed that there are no problems with the current header:
335
336    >>> print browser.contents
337    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
338    ...
339    Header fields OK
340    ...
341
342The submit button is enabled:
343
344    >>> browser.getControl('Perform import').disabled
345    False
346
347    >>> browser.getControl('Perform import').click()
348
349Step 4: See import results
350
351The import was successful:
352
353    >>> print browser.contents
354    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
355    ...Successfully processed 2 rows...
356    ...Batch processing finished...
357    ...File:...certificates_zope.mgr.csv...
358
359Batch processing certificate courses
360====================================
361
362    >>> browser.open('http://localhost/app/datacenter')
363
364Prepare a CSV file for certificate courses:
365
366    >>> open('mycertcourses.csv', 'wb').write(
367    ... """course,faculty_code,department_code,certificate_code,level,mandatory
368    ... CRS1,FAC1,DEP1,CERT1,100,True
369    ... CRS2,FAC1,DEP1,CERT1,100,True
370    ... """)
371
372Upload the file:
373
374    >>> import cStringIO
375    >>> browser.getLink('Upload CSV file').click()
376    >>> filecontents = cStringIO.StringIO(
377    ...   open('mycertcourses.csv', 'rb').read())
378    >>> filewidget = browser.getControl(name='uploadfile:file')
379    >>> filewidget.add_file(filecontents, 'text/plain', 'mycertcourses.csv')
380    >>> browser.getControl(name='SUBMIT').click()
381
382Step 1: start batch processing:
383
384    >>> browser.getLink('Batch processing').click()
385    >>> button = lookup_submit_value(
386    ...   'select', 'mycertcourses_zope.mgr.csv', browser)
387    >>> button.click()
388
389Step 2: select a processor and mode:
390
391    >>> importerselect = browser.getControl(name='importer')
392    >>> importerselect.getControl('CertificateCourse Importer').selected = True
393    >>> modeselect = browser.getControl(name='mode')
394    >>> modeselect.getControl(value='create').selected = True
395    >>> browser.getControl('Proceed to step 3').click()
396
397Step 3: Fix headerlines
398
399We get informed that there are no problems with the current header:
400
401    >>> print browser.contents
402    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
403    ...
404    Header fields OK
405    ...
406
407The submit button is enabled:
408
409    >>> browser.getControl('Perform import').disabled
410    False
411
412    >>> browser.getControl('Perform import').click()
413
414Step 4: See import results
415
416The import was successful:
417
418    >>> print browser.contents
419    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
420    ...Successfully processed 2 rows...
421    ...Batch processing finished...
422    ...File:...mycertcourses_zope.mgr.csv...
423
424
425Pending files
426=============
427
428When an error occurs during an import, two files are generated: a CSV
429file with finished files and a CSV file with pending data. Both are
430stored in the appropriate subdirectories in datacenter. We try to
431create faculties, from which one already exists.
432
433Go to datacenter page:
434
435    >>> browser.open('http://localhost/app/datacenter')
436
437Prepare a CSV file for faculties:
438
439    >>> open('newfaculties.csv', 'wb').write(
440    ... """code,title,title_prefix
441    ... FAC1,Faculty 1,faculty
442    ... FAC4,Faculty 4,school
443    ... """)
444
445Upload the file:
446
447    >>> import cStringIO
448    >>> browser.getLink('Upload CSV file').click()
449    >>> filecontents = cStringIO.StringIO(
450    ...   open('newfaculties.csv', 'rb').read())
451    >>> filewidget = browser.getControl(name='uploadfile:file')
452    >>> filewidget.add_file(filecontents, 'text/plain', 'newfaculties.csv')
453    >>> browser.getControl(name='SUBMIT').click()
454
455Step 1: start batch processing:
456
457    >>> browser.getLink('Batch processing').click()
458    >>> button = lookup_submit_value(
459    ...   'select', 'newfaculties_zope.mgr.csv', browser)
460    >>> button.click()
461
462Step 2: select a processor and mode:
463
464    >>> importerselect = browser.getControl(name='importer')
465    >>> importerselect.getControl('Faculty Importer').selected = True
466    >>> modeselect = browser.getControl(name='mode')
467    >>> modeselect.getControl(value='create').selected = True
468    >>> browser.getControl('Proceed to step 3').click()
469
470Step 3: Fix headerlines
471
472As there should be no problem with the headers, we can immediately
473perfom the import:
474
475    >>> browser.getControl('Perform import').click()
476
477One line could not be imported:
478
479    >>> print browser.contents
480    <!DOCTYPE html PUBLIC...
481    ...
482    ...Processing of 1 rows failed...
483    ...Successfully processed 1 rows...
484    ...
485
486Now there are two files as a result in datacenter storage's root and
487``finished`` dirs:
488
489    >>> pending_file = dc_path + '/newfaculties_zope.mgr.create.pending.csv'
490    >>> print open(pending_file).read()
491    title_prefix,code,title,--ERRORS--
492    faculty,FAC1,Faculty 1,This object already exists in the same container. Skipping.
493
494    >>> finished_file = dc_path + '/finished/newfaculties_zope.mgr.create.finished.csv'
495    >>> print open(finished_file).read()
496    title_prefix,code,title
497    school,FAC4,Faculty 4
498
499The finished-file contains the dataset we could import, while the
500pending file contains the dataset that failed, appended by an error
501message.
502
503
504Fixing the pending file
505-----------------------
506
507We 'edit' the pending file (setting code to ``FAC5`` and title
508appropriately, and removing the --ERROR-- column) and finish the
509import this way:
510
511    >>> open(dc_path + '/newfaculties_zope.mgr.create.pending.csv', 'wb').write(
512    ... """title_prefix,--IGNORE--,code,title
513    ... faculty,FAC5,Faculty 5
514    ... """)
515
516Step 1: start batch processing:
517
518    >>> browser.open('http://localhost/app/datacenter')
519    >>> browser.getLink('Batch processing').click()
520    >>> button = lookup_submit_value(
521    ...   'select', 'newfaculties_zope.mgr.create.pending.csv', browser)
522    >>> button.click()
523
524Step 2: select a processor and mode:
525
526    >>> importerselect = browser.getControl(name='importer')
527    >>> importerselect.getControl('Faculty Importer').selected = True
528    >>> modeselect = browser.getControl(name='mode')
529    >>> modeselect.getControl(value='create').selected = True
530    >>> browser.getControl('Proceed to step 3').click()
531
532Step 3/4: Fix headerlines and import:
533
534As there should be no problem with the headers, we can immediately
535perfom the import:
536
537    >>> browser.getControl('Perform import').click()
538
539This time everything should work:
540
541    >>> print browser.contents
542    <!DOCTYPE html PUBLIC...
543    ...
544    ...Successfully processed 1 rows...
545    ...
546
547    >>> sorted(os.listdir(dc_path))
548    ['finished', 'logs', 'unfinished']
549
550    >>> os.listdir(dc_path + '/unfinished')
551    []
552
553    >>> sorted(os.listdir(dc_path + '/finished'))
554    ['certificates_zope.mgr.create.finished.csv', ...,
555     'newfaculties_zope.mgr.create.finished.csv',
556     'newfaculties_zope.mgr.csv']
557
558
559Log Files
560=========
561
562    >>> browser.open('http://localhost/app/datacenter/logs')
563    >>> 'datacenter.log' in browser.contents
564    True
565    >>> browser.getControl('Show', index=0).click()
566    >>> '<input class="btn primary" type="submit" name="back" value="Back" />' in browser.contents
567    True
568    >>> browser.getControl('Back', index=0).click()
569    >>> browser.getControl('Back to Data Center').click()
570    >>> 'Storage path:' in browser.contents
571    True
572
573
574Clean up:
575
576    >>> import shutil
577    >>> shutil.rmtree(dc_path)
Note: See TracBrowser for help on using the repository browser.