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