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