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