[12920] | 1 | Batch Processing via Browser |
---|
[4857] | 2 | **************************** |
---|
| 3 | |
---|
[4869] | 4 | Preliminaries: |
---|
| 5 | |
---|
| 6 | We define a function that looks up a form with several submit buttons |
---|
| 7 | for the one with a given value (this functionality is missing in |
---|
| 8 | zope.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) |
---|
[4899] | 15 | ... if button.value.endswith(value): |
---|
[4869] | 16 | ... return button |
---|
| 17 | ... except IndexError: |
---|
| 18 | ... break |
---|
| 19 | ... return None |
---|
| 20 | |
---|
[4857] | 21 | Create a site: |
---|
| 22 | |
---|
[7811] | 23 | >>> from waeup.kofa.app import University |
---|
[4857] | 24 | >>> getRootFolder()['app'] = University() |
---|
[9312] | 25 | >>> from zope.component.hooks import setSite |
---|
| 26 | >>> setSite(getRootFolder()['app']) |
---|
[4857] | 27 | |
---|
| 28 | Create a datacenter storage path: |
---|
| 29 | |
---|
| 30 | >>> import os |
---|
| 31 | >>> import tempfile |
---|
| 32 | >>> dc_path = tempfile.mkdtemp() |
---|
| 33 | |
---|
| 34 | Log in: |
---|
| 35 | |
---|
| 36 | >>> from zope.testbrowser.testing import Browser |
---|
| 37 | >>> browser = Browser() |
---|
| 38 | >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 39 | >>> browser.handleErrors = False |
---|
| 40 | |
---|
| 41 | Set datacenter path and deselect moving old data: |
---|
| 42 | |
---|
| 43 | >>> browser.open('http://localhost/app') |
---|
| 44 | >>> browser.getLink('Data Center').click() |
---|
| 45 | >>> browser.getLink('Edit settings').click() |
---|
| 46 | >>> browser.getControl(name='newpath').value = dc_path |
---|
| 47 | >>> browser.getControl(name='move').value = False |
---|
| 48 | >>> browser.getControl(name='save').click() |
---|
| 49 | |
---|
[6611] | 50 | Set non-usable datacenter path: |
---|
| 51 | |
---|
| 52 | >>> browser.getLink('Edit settings').click() |
---|
| 53 | >>> browser.getControl(name='newpath').value = '/' |
---|
| 54 | >>> browser.getControl(name='save').click() |
---|
| 55 | >>> 'Given storage path cannot be used.' in browser.contents |
---|
| 56 | True |
---|
[11254] | 57 | >>> browser.getControl('Back to Data Center').click() |
---|
[6611] | 58 | |
---|
| 59 | |
---|
[12920] | 60 | Batch Processing Faculties |
---|
[4857] | 61 | ========================== |
---|
| 62 | |
---|
| 63 | Go to datacenter page: |
---|
| 64 | |
---|
| 65 | >>> browser.open('http://localhost/app/datacenter') |
---|
| 66 | |
---|
[9919] | 67 | Prepare a CSV file for faculties (extended ascii values are accepted): |
---|
[4857] | 68 | |
---|
| 69 | >>> open('faculties.csv', 'wb').write( |
---|
[6823] | 70 | ... """code,title,title_prefix |
---|
| 71 | ... FAC1,Faculty 1,faculty |
---|
| 72 | ... FAC2,Faculty 2,institute |
---|
[9919] | 73 | ... FAC3,Fäcülty 3,school |
---|
[4857] | 74 | ... """) |
---|
| 75 | |
---|
| 76 | Upload the file: |
---|
| 77 | |
---|
| 78 | >>> import cStringIO |
---|
[9024] | 79 | >>> browser.getLink('Upload data').click() |
---|
[4857] | 80 | >>> filecontents = cStringIO.StringIO( |
---|
| 81 | ... open('faculties.csv', 'rb').read()) |
---|
| 82 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 83 | >>> filewidget.add_file(filecontents, 'text/plain', 'faculties.csv') |
---|
| 84 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 85 | |
---|
| 86 | Step 1: start batch processing: |
---|
| 87 | |
---|
[13431] | 88 | >>> browser.getLink('Process data').click() |
---|
[13394] | 89 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[4869] | 90 | >>> button = lookup_submit_value( |
---|
| 91 | ... 'select', 'faculties_zope.mgr.csv', browser) |
---|
| 92 | >>> button.click() |
---|
[4857] | 93 | |
---|
| 94 | Step 2: select a processor and mode: |
---|
| 95 | |
---|
| 96 | >>> importerselect = browser.getControl(name='importer') |
---|
| 97 | >>> importerselect.displayOptions |
---|
[12439] | 98 | ['AccessCodeBatch Processor', |
---|
| 99 | 'AccessCode Processor', |
---|
[13872] | 100 | 'ApplicantOnlinePayment Processor', |
---|
[12439] | 101 | 'Applicant Processor', |
---|
[17772] | 102 | 'ApplicantRefereeReport Processor', |
---|
[12439] | 103 | 'ApplicantsContainer Processor', |
---|
[13431] | 104 | 'Bed Processor (update only)', |
---|
[12439] | 105 | 'CertificateCourse Processor', |
---|
| 106 | 'Certificate Processor', |
---|
[17755] | 107 | 'SessionConfiguration Processor', |
---|
[9420] | 108 | 'Course Processor', |
---|
[9418] | 109 | 'CourseTicket Processor', |
---|
[12439] | 110 | 'Department Processor', |
---|
| 111 | 'Faculty Processor', |
---|
[9203] | 112 | 'Hostel Processor', |
---|
[12439] | 113 | 'Public HTML Document Processor', |
---|
| 114 | 'StudentOnlinePayment Processor', |
---|
| 115 | 'Public PDF Document Processor', |
---|
| 116 | 'Public REST Document Processor', |
---|
| 117 | 'Student Processor', |
---|
[16834] | 118 | 'StudentStudyCourse Processor', |
---|
[8973] | 119 | 'StudentStudyLevel Processor', |
---|
| 120 | 'User Processor', |
---|
[9418] | 121 | 'Verdict Processor (special processor, update only)'] |
---|
[4857] | 122 | |
---|
[7933] | 123 | >>> importerselect.getControl('Faculty Processor').selected = True |
---|
[4857] | 124 | |
---|
| 125 | >>> modeselect = browser.getControl(name='mode') |
---|
| 126 | >>> modeselect.options |
---|
| 127 | ['create', 'update', 'remove'] |
---|
| 128 | |
---|
| 129 | >>> modeselect.getControl(value='create').selected = True |
---|
[7705] | 130 | >>> browser.getControl('Proceed to step 3').click() |
---|
[4857] | 131 | |
---|
| 132 | Step 3: Fix headerlines |
---|
| 133 | |
---|
| 134 | We get informed that there are no problems with the current header: |
---|
| 135 | |
---|
| 136 | >>> print browser.contents |
---|
| 137 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 138 | ... |
---|
| 139 | Header fields OK |
---|
| 140 | ... |
---|
| 141 | |
---|
| 142 | The submit button is enabled: |
---|
| 143 | |
---|
[7705] | 144 | >>> browser.getControl('Perform import').disabled |
---|
[4857] | 145 | False |
---|
| 146 | |
---|
[7705] | 147 | >>> browser.getControl('Perform import').click() |
---|
[4857] | 148 | |
---|
| 149 | Step 4: See import results |
---|
| 150 | |
---|
| 151 | The import was successful: |
---|
| 152 | |
---|
| 153 | >>> print browser.contents |
---|
| 154 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 155 | ...Successfully processed 3 rows... |
---|
| 156 | ...Batch processing finished... |
---|
| 157 | ...File:...faculties_zope.mgr.csv... |
---|
| 158 | |
---|
[7749] | 159 | We can grep the entries generated in logfile: |
---|
[4857] | 160 | |
---|
[10099] | 161 | >>> browser.open('http://localhost/app/datacenter/logs') |
---|
| 162 | >>> browser.getControl('Show', index=0).click() |
---|
[4857] | 163 | >>> print browser.contents |
---|
| 164 | <!DOCTYPE ... |
---|
[10207] | 165 | ...<h1 class="kofa-content-label">Logfile datacenter.log</h1>... |
---|
[4857] | 166 | |
---|
[7749] | 167 | >>> browser.getControl(name='query').value = "zope.mgr" |
---|
| 168 | >>> browser.getControl('Search').click() |
---|
[9739] | 169 | >>> 'zope.mgr - processed' in browser.contents |
---|
[7749] | 170 | True |
---|
[4857] | 171 | |
---|
[7749] | 172 | |
---|
[12920] | 173 | Batch Processing Departments |
---|
[4857] | 174 | ============================ |
---|
| 175 | |
---|
| 176 | >>> browser.open('http://localhost/app/datacenter') |
---|
| 177 | |
---|
| 178 | Prepare a CSV file for departments: |
---|
| 179 | |
---|
| 180 | >>> open('departments.csv', 'wb').write( |
---|
[6823] | 181 | ... """code,faculty_code,title,title_prefix |
---|
| 182 | ... DEP1,FAC1,Department 1,department |
---|
| 183 | ... DEP2,FAC2,Department 2,centre |
---|
[4857] | 184 | ... """) |
---|
| 185 | |
---|
| 186 | Upload the file: |
---|
| 187 | |
---|
| 188 | >>> import cStringIO |
---|
[9024] | 189 | >>> browser.getLink('Upload data').click() |
---|
[4857] | 190 | >>> filecontents = cStringIO.StringIO( |
---|
| 191 | ... open('departments.csv', 'rb').read()) |
---|
| 192 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 193 | >>> filewidget.add_file(filecontents, 'text/plain', 'departments.csv') |
---|
| 194 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 195 | |
---|
| 196 | Step 1: start batch processing: |
---|
| 197 | |
---|
[13431] | 198 | >>> browser.getLink('Process data').click() |
---|
[13394] | 199 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[4869] | 200 | >>> button = lookup_submit_value( |
---|
| 201 | ... 'select', 'departments_zope.mgr.csv', browser) |
---|
| 202 | >>> button.click() |
---|
[4857] | 203 | |
---|
| 204 | Step 2: select a processor and mode: |
---|
| 205 | |
---|
| 206 | >>> importerselect = browser.getControl(name='importer') |
---|
[7933] | 207 | >>> importerselect.getControl('Department Processor').selected = True |
---|
[4857] | 208 | >>> modeselect = browser.getControl(name='mode') |
---|
| 209 | >>> modeselect.getControl(value='create').selected = True |
---|
[7705] | 210 | >>> browser.getControl('Proceed to step 3').click() |
---|
[4857] | 211 | |
---|
| 212 | Step 3: Fix headerlines |
---|
| 213 | |
---|
| 214 | We get informed that there are no problems with the current header: |
---|
| 215 | |
---|
| 216 | >>> print browser.contents |
---|
| 217 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 218 | ... |
---|
| 219 | Header fields OK |
---|
| 220 | ... |
---|
| 221 | |
---|
| 222 | The submit button is enabled: |
---|
| 223 | |
---|
[7705] | 224 | >>> browser.getControl('Perform import').disabled |
---|
[4857] | 225 | False |
---|
| 226 | |
---|
[7705] | 227 | >>> browser.getControl('Perform import').click() |
---|
[4857] | 228 | |
---|
| 229 | Step 4: See import results |
---|
| 230 | |
---|
| 231 | The import was successful: |
---|
| 232 | |
---|
| 233 | >>> print browser.contents |
---|
| 234 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 235 | ...Successfully processed 2 rows... |
---|
| 236 | ...Batch processing finished... |
---|
| 237 | ...File:...departments_zope.mgr.csv... |
---|
| 238 | |
---|
[12920] | 239 | Batch Processing Courses |
---|
[4857] | 240 | ======================== |
---|
| 241 | |
---|
| 242 | >>> browser.open('http://localhost/app/datacenter') |
---|
| 243 | |
---|
| 244 | Prepare a CSV file for courses: |
---|
| 245 | |
---|
| 246 | >>> open('courses.csv', 'wb').write( |
---|
| 247 | ... """code,faculty_code,department_code,title,level,passmark,credits,semester |
---|
| 248 | ... CRS1,FAC1,DEP1,Course 1,100,40,2,1 |
---|
| 249 | ... CRS2,FAC1,DEP1,Course 2,100,40,2,2 |
---|
| 250 | ... """) |
---|
| 251 | |
---|
| 252 | Upload the file: |
---|
| 253 | |
---|
| 254 | >>> import cStringIO |
---|
[9024] | 255 | >>> browser.getLink('Upload data').click() |
---|
[4857] | 256 | >>> filecontents = cStringIO.StringIO( |
---|
| 257 | ... open('courses.csv', 'rb').read()) |
---|
| 258 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 259 | >>> filewidget.add_file(filecontents, 'text/plain', 'courses.csv') |
---|
| 260 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 261 | |
---|
| 262 | Step 1: start batch processing: |
---|
| 263 | |
---|
[13431] | 264 | >>> browser.getLink('Process data').click() |
---|
[13394] | 265 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[4869] | 266 | >>> button = lookup_submit_value( |
---|
| 267 | ... 'select', 'courses_zope.mgr.csv', browser) |
---|
| 268 | >>> button.click() |
---|
[4857] | 269 | |
---|
| 270 | Step 2: select a processor and mode: |
---|
| 271 | |
---|
| 272 | >>> importerselect = browser.getControl(name='importer') |
---|
[7954] | 273 | >>> importerselect.getControl('Course Processor', index=1).selected = True |
---|
[4857] | 274 | >>> modeselect = browser.getControl(name='mode') |
---|
| 275 | >>> modeselect.getControl(value='create').selected = True |
---|
[7705] | 276 | >>> browser.getControl('Proceed to step 3').click() |
---|
[4857] | 277 | |
---|
| 278 | Step 3: Fix headerlines |
---|
| 279 | |
---|
| 280 | We get informed that there are no problems with the current header: |
---|
| 281 | |
---|
| 282 | >>> print browser.contents |
---|
| 283 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 284 | ... |
---|
| 285 | Header fields OK |
---|
| 286 | ... |
---|
| 287 | |
---|
| 288 | The submit button is enabled: |
---|
| 289 | |
---|
[7705] | 290 | >>> browser.getControl('Perform import').disabled |
---|
[4857] | 291 | False |
---|
| 292 | |
---|
[7705] | 293 | >>> browser.getControl('Perform import').click() |
---|
[4857] | 294 | |
---|
| 295 | Step 4: See import results |
---|
| 296 | |
---|
| 297 | The import was successful: |
---|
| 298 | |
---|
| 299 | >>> print browser.contents |
---|
| 300 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 301 | ...Successfully processed 2 rows... |
---|
| 302 | ...Batch processing finished... |
---|
| 303 | ...File:...courses_zope.mgr.csv... |
---|
| 304 | |
---|
[12920] | 305 | Batch Processing Certificates |
---|
[4857] | 306 | ============================= |
---|
| 307 | |
---|
| 308 | >>> browser.open('http://localhost/app/datacenter') |
---|
| 309 | |
---|
| 310 | Prepare a CSV file for certificates: |
---|
| 311 | |
---|
| 312 | >>> open('certificates.csv', 'wb').write( |
---|
[5947] | 313 | ... """code,faculty_code,department_code,title,study_mode,start_level,end_level,application_category |
---|
[8472] | 314 | ... CERT1,FAC1,DEP1,Certificate 1,pg_ft,999,999,basic |
---|
[5986] | 315 | ... CERT2,FAC1,DEP1,Certificate 2,ug_ft,200,300,cest |
---|
[4857] | 316 | ... """) |
---|
| 317 | |
---|
| 318 | Upload the file: |
---|
| 319 | |
---|
| 320 | >>> import cStringIO |
---|
[9024] | 321 | >>> browser.getLink('Upload data').click() |
---|
[4857] | 322 | >>> filecontents = cStringIO.StringIO( |
---|
| 323 | ... open('certificates.csv', 'rb').read()) |
---|
| 324 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 325 | >>> filewidget.add_file(filecontents, 'text/plain', 'certificates.csv') |
---|
| 326 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 327 | |
---|
| 328 | Step 1: start batch processing: |
---|
| 329 | |
---|
[13431] | 330 | >>> browser.getLink('Process data').click() |
---|
[13394] | 331 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[4869] | 332 | >>> button = lookup_submit_value( |
---|
| 333 | ... 'select', 'certificates_zope.mgr.csv', browser) |
---|
| 334 | >>> button.click() |
---|
[4857] | 335 | |
---|
[4869] | 336 | |
---|
[4857] | 337 | Step 2: select a processor and mode: |
---|
| 338 | |
---|
| 339 | >>> importerselect = browser.getControl(name='importer') |
---|
[7933] | 340 | >>> importerselect.getControl('Certificate Processor').selected = True |
---|
[4857] | 341 | >>> modeselect = browser.getControl(name='mode') |
---|
| 342 | >>> modeselect.getControl(value='create').selected = True |
---|
[7705] | 343 | >>> browser.getControl('Proceed to step 3').click() |
---|
[4857] | 344 | |
---|
| 345 | Step 3: Fix headerlines |
---|
| 346 | |
---|
| 347 | We get informed that there are no problems with the current header: |
---|
| 348 | |
---|
| 349 | >>> print browser.contents |
---|
| 350 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 351 | ... |
---|
| 352 | Header fields OK |
---|
| 353 | ... |
---|
| 354 | |
---|
| 355 | The submit button is enabled: |
---|
| 356 | |
---|
[7705] | 357 | >>> browser.getControl('Perform import').disabled |
---|
[4857] | 358 | False |
---|
| 359 | |
---|
[7705] | 360 | >>> browser.getControl('Perform import').click() |
---|
[4857] | 361 | |
---|
| 362 | Step 4: See import results |
---|
| 363 | |
---|
| 364 | The import was successful: |
---|
| 365 | |
---|
| 366 | >>> print browser.contents |
---|
| 367 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 368 | ...Successfully processed 2 rows... |
---|
| 369 | ...Batch processing finished... |
---|
| 370 | ...File:...certificates_zope.mgr.csv... |
---|
| 371 | |
---|
[12920] | 372 | Batch Processing Certificate Courses |
---|
[4857] | 373 | ==================================== |
---|
| 374 | |
---|
| 375 | >>> browser.open('http://localhost/app/datacenter') |
---|
| 376 | |
---|
| 377 | Prepare a CSV file for certificate courses: |
---|
| 378 | |
---|
| 379 | >>> open('mycertcourses.csv', 'wb').write( |
---|
[7665] | 380 | ... """course,faculty_code,department_code,certificate_code,level,mandatory |
---|
[4857] | 381 | ... CRS1,FAC1,DEP1,CERT1,100,True |
---|
| 382 | ... CRS2,FAC1,DEP1,CERT1,100,True |
---|
| 383 | ... """) |
---|
| 384 | |
---|
| 385 | Upload the file: |
---|
| 386 | |
---|
| 387 | >>> import cStringIO |
---|
[9024] | 388 | >>> browser.getLink('Upload data').click() |
---|
[4857] | 389 | >>> filecontents = cStringIO.StringIO( |
---|
| 390 | ... open('mycertcourses.csv', 'rb').read()) |
---|
| 391 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 392 | >>> filewidget.add_file(filecontents, 'text/plain', 'mycertcourses.csv') |
---|
| 393 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 394 | |
---|
| 395 | Step 1: start batch processing: |
---|
| 396 | |
---|
[13431] | 397 | >>> browser.getLink('Process data').click() |
---|
[13394] | 398 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[4869] | 399 | >>> button = lookup_submit_value( |
---|
| 400 | ... 'select', 'mycertcourses_zope.mgr.csv', browser) |
---|
| 401 | >>> button.click() |
---|
[4857] | 402 | |
---|
| 403 | Step 2: select a processor and mode: |
---|
| 404 | |
---|
| 405 | >>> importerselect = browser.getControl(name='importer') |
---|
[7933] | 406 | >>> importerselect.getControl('CertificateCourse Processor').selected = True |
---|
[4857] | 407 | >>> modeselect = browser.getControl(name='mode') |
---|
| 408 | >>> modeselect.getControl(value='create').selected = True |
---|
[7705] | 409 | >>> browser.getControl('Proceed to step 3').click() |
---|
[4857] | 410 | |
---|
| 411 | Step 3: Fix headerlines |
---|
| 412 | |
---|
| 413 | We get informed that there are no problems with the current header: |
---|
| 414 | |
---|
| 415 | >>> print browser.contents |
---|
| 416 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 417 | ... |
---|
| 418 | Header fields OK |
---|
| 419 | ... |
---|
| 420 | |
---|
| 421 | The submit button is enabled: |
---|
| 422 | |
---|
[7705] | 423 | >>> browser.getControl('Perform import').disabled |
---|
[4857] | 424 | False |
---|
| 425 | |
---|
[7705] | 426 | >>> browser.getControl('Perform import').click() |
---|
[4857] | 427 | |
---|
| 428 | Step 4: See import results |
---|
| 429 | |
---|
| 430 | The import was successful: |
---|
| 431 | |
---|
| 432 | >>> print browser.contents |
---|
| 433 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 434 | ...Successfully processed 2 rows... |
---|
| 435 | ...Batch processing finished... |
---|
| 436 | ...File:...mycertcourses_zope.mgr.csv... |
---|
| 437 | |
---|
[12920] | 438 | Batch Processing Users |
---|
[8973] | 439 | ====================== |
---|
[4857] | 440 | |
---|
[8973] | 441 | >>> browser.open('http://localhost/app/datacenter') |
---|
| 442 | |
---|
[9203] | 443 | Prepare a CSV file for users: |
---|
[8973] | 444 | |
---|
| 445 | >>> open('users.csv', 'wb').write( |
---|
[8976] | 446 | ... """name,title,public_name,email,phone,roles |
---|
[9310] | 447 | ... uli,Uli Fouquet,Chief Developer,uli@abc.de,+49-234-567,[] |
---|
| 448 | ... henrik,Henrik Bettermann,Admin,henrik@abc.de,+49-234-567,"['waeup.PortalManager', 'waeup.ImportManager']" |
---|
[12190] | 449 | ... anne,Anne Palina,,anne@abc.de,+49-234-567,"['waeup.Nonsense']" |
---|
[8973] | 450 | ... """) |
---|
| 451 | |
---|
| 452 | Upload the file: |
---|
| 453 | |
---|
| 454 | >>> import cStringIO |
---|
[9024] | 455 | >>> browser.getLink('Upload data').click() |
---|
[8973] | 456 | >>> filecontents = cStringIO.StringIO( |
---|
| 457 | ... open('users.csv', 'rb').read()) |
---|
| 458 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 459 | >>> filewidget.add_file(filecontents, 'text/plain', 'users.csv') |
---|
| 460 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 461 | |
---|
| 462 | Step 1: start batch processing: |
---|
| 463 | |
---|
[13431] | 464 | >>> browser.getLink('Process data').click() |
---|
[13394] | 465 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[8973] | 466 | >>> button = lookup_submit_value( |
---|
| 467 | ... 'select', 'users_zope.mgr.csv', browser) |
---|
| 468 | >>> button.click() |
---|
| 469 | |
---|
| 470 | Step 2: select a processor and mode: |
---|
| 471 | |
---|
| 472 | >>> importerselect = browser.getControl(name='importer') |
---|
| 473 | >>> importerselect.getControl('User Processor').selected = True |
---|
| 474 | >>> modeselect = browser.getControl(name='mode') |
---|
| 475 | >>> modeselect.getControl(value='create').selected = True |
---|
| 476 | >>> browser.getControl('Proceed to step 3').click() |
---|
| 477 | |
---|
| 478 | Step 3: Fix headerlines |
---|
| 479 | |
---|
| 480 | We get informed that there are no problems with the current header: |
---|
| 481 | |
---|
| 482 | >>> print browser.contents |
---|
| 483 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 484 | ... |
---|
| 485 | Header fields OK |
---|
| 486 | ... |
---|
| 487 | |
---|
| 488 | The submit button is enabled: |
---|
| 489 | |
---|
| 490 | >>> browser.getControl('Perform import').disabled |
---|
| 491 | False |
---|
| 492 | |
---|
| 493 | >>> browser.getControl('Perform import').click() |
---|
| 494 | |
---|
| 495 | Step 4: See import results |
---|
| 496 | |
---|
| 497 | The import was successful: |
---|
| 498 | |
---|
| 499 | >>> print browser.contents |
---|
| 500 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 501 | ...Successfully processed 2 rows... |
---|
| 502 | ...Batch processing finished... |
---|
| 503 | ...File:...users_zope.mgr.csv... |
---|
| 504 | |
---|
[9310] | 505 | User henrik has got the global roles: |
---|
| 506 | |
---|
| 507 | >>> henrik = getRootFolder()['app']['users']['henrik'] |
---|
| 508 | >>> henrik.roles |
---|
[9312] | 509 | ['waeup.PortalManager', 'waeup.AcademicsOfficer', 'waeup.ImportManager'] |
---|
[9310] | 510 | |
---|
[12920] | 511 | Pending Files |
---|
[4899] | 512 | ============= |
---|
| 513 | |
---|
| 514 | When an error occurs during an import, two files are generated: a CSV |
---|
| 515 | file with finished files and a CSV file with pending data. Both are |
---|
| 516 | stored in the appropriate subdirectories in datacenter. We try to |
---|
| 517 | create faculties, from which one already exists. |
---|
| 518 | |
---|
| 519 | Go to datacenter page: |
---|
| 520 | |
---|
| 521 | >>> browser.open('http://localhost/app/datacenter') |
---|
| 522 | |
---|
| 523 | Prepare a CSV file for faculties: |
---|
| 524 | |
---|
| 525 | >>> open('newfaculties.csv', 'wb').write( |
---|
[6823] | 526 | ... """code,title,title_prefix |
---|
| 527 | ... FAC1,Faculty 1,faculty |
---|
| 528 | ... FAC4,Faculty 4,school |
---|
[12191] | 529 | ... FAC 5,Faculty 5,faculty |
---|
[4899] | 530 | ... """) |
---|
| 531 | |
---|
| 532 | Upload the file: |
---|
| 533 | |
---|
| 534 | >>> import cStringIO |
---|
[9024] | 535 | >>> browser.getLink('Upload data').click() |
---|
[4899] | 536 | >>> filecontents = cStringIO.StringIO( |
---|
| 537 | ... open('newfaculties.csv', 'rb').read()) |
---|
| 538 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 539 | >>> filewidget.add_file(filecontents, 'text/plain', 'newfaculties.csv') |
---|
| 540 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 541 | |
---|
[9310] | 542 | Since we now have a user with waeup.ImportManager role, an email has been sent: |
---|
| 543 | >>> print browser.contents |
---|
| 544 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 545 | ... |
---|
| 546 | ...All import managers have been notified by email... |
---|
| 547 | ... |
---|
| 548 | |
---|
[4899] | 549 | Step 1: start batch processing: |
---|
| 550 | |
---|
[13431] | 551 | >>> browser.getLink('Process data').click() |
---|
[13394] | 552 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[4899] | 553 | >>> button = lookup_submit_value( |
---|
| 554 | ... 'select', 'newfaculties_zope.mgr.csv', browser) |
---|
| 555 | >>> button.click() |
---|
| 556 | |
---|
| 557 | Step 2: select a processor and mode: |
---|
| 558 | |
---|
| 559 | >>> importerselect = browser.getControl(name='importer') |
---|
[7933] | 560 | >>> importerselect.getControl('Faculty Processor').selected = True |
---|
[4899] | 561 | >>> modeselect = browser.getControl(name='mode') |
---|
| 562 | >>> modeselect.getControl(value='create').selected = True |
---|
[7705] | 563 | >>> browser.getControl('Proceed to step 3').click() |
---|
[4899] | 564 | |
---|
| 565 | Step 3: Fix headerlines |
---|
| 566 | |
---|
| 567 | As there should be no problem with the headers, we can immediately |
---|
| 568 | perfom the import: |
---|
| 569 | |
---|
[7705] | 570 | >>> browser.getControl('Perform import').click() |
---|
[4899] | 571 | |
---|
[12191] | 572 | Two lines could not be imported: |
---|
[4899] | 573 | |
---|
| 574 | >>> print browser.contents |
---|
| 575 | <!DOCTYPE html PUBLIC... |
---|
| 576 | ... |
---|
[12191] | 577 | ...Processing of 2 rows failed... |
---|
[4899] | 578 | ...Successfully processed 1 rows... |
---|
| 579 | ... |
---|
| 580 | |
---|
| 581 | Now there are two files as a result in datacenter storage's root and |
---|
| 582 | ``finished`` dirs: |
---|
| 583 | |
---|
[4998] | 584 | >>> pending_file = dc_path + '/newfaculties_zope.mgr.create.pending.csv' |
---|
[4899] | 585 | >>> print open(pending_file).read() |
---|
[6824] | 586 | title_prefix,code,title,--ERRORS-- |
---|
[12868] | 587 | faculty,FAC1,Faculty 1,This object already exists. |
---|
[12415] | 588 | faculty,FAC 5,Faculty 5,code: Invalid input |
---|
[4899] | 589 | |
---|
[4998] | 590 | >>> finished_file = dc_path + '/finished/newfaculties_zope.mgr.create.finished.csv' |
---|
[4899] | 591 | >>> print open(finished_file).read() |
---|
[6824] | 592 | title_prefix,code,title |
---|
[6823] | 593 | school,FAC4,Faculty 4 |
---|
[4899] | 594 | |
---|
| 595 | The finished-file contains the dataset we could import, while the |
---|
| 596 | pending file contains the dataset that failed, appended by an error |
---|
| 597 | message. |
---|
| 598 | |
---|
| 599 | |
---|
[12920] | 600 | Fixing the Pending File |
---|
[4981] | 601 | ----------------------- |
---|
| 602 | |
---|
| 603 | We 'edit' the pending file (setting code to ``FAC5`` and title |
---|
| 604 | appropriately, and removing the --ERROR-- column) and finish the |
---|
| 605 | import this way: |
---|
| 606 | |
---|
[4998] | 607 | >>> open(dc_path + '/newfaculties_zope.mgr.create.pending.csv', 'wb').write( |
---|
[4981] | 608 | ... """title_prefix,--IGNORE--,code,title |
---|
[12191] | 609 | ... faculty,,FAC5,Faculty 5 |
---|
[4981] | 610 | ... """) |
---|
| 611 | |
---|
| 612 | Step 1: start batch processing: |
---|
| 613 | |
---|
| 614 | >>> browser.open('http://localhost/app/datacenter') |
---|
[13431] | 615 | >>> browser.getLink('Process data').click() |
---|
[13394] | 616 | >>> browser.getLink('Switch maintenance mode').click() |
---|
[4981] | 617 | >>> button = lookup_submit_value( |
---|
[4998] | 618 | ... 'select', 'newfaculties_zope.mgr.create.pending.csv', browser) |
---|
[4981] | 619 | >>> button.click() |
---|
| 620 | |
---|
| 621 | Step 2: select a processor and mode: |
---|
| 622 | |
---|
| 623 | >>> importerselect = browser.getControl(name='importer') |
---|
[7933] | 624 | >>> importerselect.getControl('Faculty Processor').selected = True |
---|
[4981] | 625 | >>> modeselect = browser.getControl(name='mode') |
---|
| 626 | >>> modeselect.getControl(value='create').selected = True |
---|
[7705] | 627 | >>> browser.getControl('Proceed to step 3').click() |
---|
[4981] | 628 | |
---|
| 629 | Step 3/4: Fix headerlines and import: |
---|
| 630 | |
---|
| 631 | As there should be no problem with the headers, we can immediately |
---|
| 632 | perfom the import: |
---|
| 633 | |
---|
[7705] | 634 | >>> browser.getControl('Perform import').click() |
---|
[4981] | 635 | |
---|
| 636 | This time everything should work: |
---|
| 637 | |
---|
| 638 | >>> print browser.contents |
---|
| 639 | <!DOCTYPE html PUBLIC... |
---|
| 640 | ... |
---|
| 641 | ...Successfully processed 1 rows... |
---|
| 642 | ... |
---|
| 643 | |
---|
[12190] | 644 | Oh no, we forgot Anne Palina. Her user record was not imported because |
---|
| 645 | she has a non-existent role: |
---|
| 646 | |
---|
[4981] | 647 | >>> sorted(os.listdir(dc_path)) |
---|
[15416] | 648 | ['deleted', 'finished', 'graduated', 'logs', 'unfinished', 'users_zope.mgr.create.pending.csv'] |
---|
[4981] | 649 | |
---|
| 650 | >>> os.listdir(dc_path + '/unfinished') |
---|
[12190] | 651 | ['users_zope.mgr.csv'] |
---|
[4981] | 652 | |
---|
[12190] | 653 | >>> pending_file = dc_path + '/users_zope.mgr.create.pending.csv' |
---|
| 654 | >>> print open(pending_file).read() |
---|
| 655 | name,roles,title,public_name,phone,email,--ERRORS-- |
---|
[12981] | 656 | anne,['waeup.Nonsense'],Anne Palina,<IGNORE>,+49-234-567,anne@abc.de,roles: invalid role |
---|
[12190] | 657 | |
---|
| 658 | There are many finished-files: |
---|
| 659 | |
---|
[4981] | 660 | >>> sorted(os.listdir(dc_path + '/finished')) |
---|
[8372] | 661 | ['certificates_zope.mgr.create.finished.csv', ..., |
---|
[12190] | 662 | 'users_zope.mgr.create.finished.csv'] |
---|
[4981] | 663 | |
---|
[9023] | 664 | Processed (finished) Files |
---|
| 665 | ========================== |
---|
[4981] | 666 | |
---|
[9023] | 667 | >>> browser.open('http://localhost/app/datacenter/processed') |
---|
[11460] | 668 | >>> 'download?filename=finished/certificates_zope.mgr.create.finished.csv' in browser.contents |
---|
[9023] | 669 | True |
---|
| 670 | |
---|
[6608] | 671 | Log Files |
---|
| 672 | ========= |
---|
| 673 | |
---|
| 674 | >>> browser.open('http://localhost/app/datacenter/logs') |
---|
| 675 | >>> 'datacenter.log' in browser.contents |
---|
| 676 | True |
---|
[6754] | 677 | >>> browser.getControl('Show', index=0).click() |
---|
[6611] | 678 | >>> browser.getControl('Back', index=0).click() |
---|
| 679 | >>> browser.getControl('Back to Data Center').click() |
---|
| 680 | >>> 'Storage path:' in browser.contents |
---|
| 681 | True |
---|
[6608] | 682 | |
---|
| 683 | |
---|
[4857] | 684 | Clean up: |
---|
| 685 | |
---|
| 686 | >>> import shutil |
---|
[6734] | 687 | >>> shutil.rmtree(dc_path) |
---|