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