| 1 | ## $Id: test_browser.py 14255 2016-11-03 08:23:24Z henrik $ |
|---|
| 2 | ## |
|---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
|---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
|---|
| 5 | ## it under the terms of the GNU General Public License as published by |
|---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | ## (at your option) any later version. |
|---|
| 8 | ## |
|---|
| 9 | ## This program is distributed in the hope that it will be useful, |
|---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | ## GNU General Public License for more details. |
|---|
| 13 | ## |
|---|
| 14 | ## You should have received a copy of the GNU General Public License |
|---|
| 15 | ## along with this program; if not, write to the Free Software |
|---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | ## |
|---|
| 18 | import os |
|---|
| 19 | import shutil |
|---|
| 20 | import tempfile |
|---|
| 21 | from mechanize import LinkNotFoundError |
|---|
| 22 | from StringIO import StringIO |
|---|
| 23 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo |
|---|
| 24 | from zope.component.hooks import setSite, clearSite |
|---|
| 25 | from zope.component import getUtility, createObject |
|---|
| 26 | from zope.interface import verify |
|---|
| 27 | from waeup.kofa.app import University |
|---|
| 28 | from waeup.kofa.students.tests.test_browser import ( |
|---|
| 29 | StudentsFullSetup, SAMPLE_IMAGE) |
|---|
| 30 | from waeup.kofa.students.accommodation import BedTicket |
|---|
| 31 | from waeup.kofa.testing import FunctionalTestCase |
|---|
| 32 | from waeup.kofa.interfaces import ( |
|---|
| 33 | IExtFileStore, IFileStoreNameChooser) |
|---|
| 34 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
|---|
| 35 | from waeup.kofa.students.interfaces import IStudentsUtils |
|---|
| 36 | from waeup.kwarapoly.testing import FunctionalLayer |
|---|
| 37 | from waeup.kwarapoly.students.utils import ( |
|---|
| 38 | local_nonlocal, arts_science, we_ft) |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | class StudentProcessorTest(FunctionalTestCase): |
|---|
| 42 | """Perform some batching tests. |
|---|
| 43 | """ |
|---|
| 44 | |
|---|
| 45 | layer = FunctionalLayer |
|---|
| 46 | |
|---|
| 47 | def setUp(self): |
|---|
| 48 | super(StudentProcessorTest, self).setUp() |
|---|
| 49 | # Setup a sample site for each test |
|---|
| 50 | app = University() |
|---|
| 51 | self.dc_root = tempfile.mkdtemp() |
|---|
| 52 | app['datacenter'].setStoragePath(self.dc_root) |
|---|
| 53 | |
|---|
| 54 | # Prepopulate the ZODB... |
|---|
| 55 | self.getRootFolder()['app'] = app |
|---|
| 56 | # we add the site immediately after creation to the |
|---|
| 57 | # ZODB. Catalogs and other local utilities are not setup |
|---|
| 58 | # before that step. |
|---|
| 59 | self.app = self.getRootFolder()['app'] |
|---|
| 60 | # Set site here. Some of the following setup code might need |
|---|
| 61 | # to access grok.getSite() and should get our new app then |
|---|
| 62 | setSite(app) |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | def tearDown(self): |
|---|
| 66 | super(StudentProcessorTest, self).tearDown() |
|---|
| 67 | shutil.rmtree(self.workdir) |
|---|
| 68 | shutil.rmtree(self.dc_root) |
|---|
| 69 | clearSite() |
|---|
| 70 | return |
|---|
| 71 | |
|---|
| 72 | class StudentUITests(StudentsFullSetup): |
|---|
| 73 | """Tests for customized student class views and pages |
|---|
| 74 | """ |
|---|
| 75 | |
|---|
| 76 | layer = FunctionalLayer |
|---|
| 77 | |
|---|
| 78 | def setUp(self): |
|---|
| 79 | super(StudentUITests, self).setUp() |
|---|
| 80 | self.certificate.study_mode = 'hnd_ft' |
|---|
| 81 | bedticket = BedTicket() |
|---|
| 82 | bedticket.booking_session = 2004 |
|---|
| 83 | bedticket.bed_type = u'any bed type' |
|---|
| 84 | bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
|---|
| 85 | bedticket.bed_coordinates = u'My bed coordinates' |
|---|
| 86 | self.student['accommodation'].addBedTicket(bedticket) |
|---|
| 87 | |
|---|
| 88 | self.app['configuration']['2004'].gown_fee = 150.0 |
|---|
| 89 | self.app['configuration']['2004'].transfer_fee = 90.0 |
|---|
| 90 | self.app['configuration']['2004'].clearance_fee = 120.0 |
|---|
| 91 | self.app['configuration']['2004'].booking_fee = 150.0 |
|---|
| 92 | self.app['configuration']['2004'].maint_fee = 180.0 |
|---|
| 93 | self.app['configuration']['2004'].certificate_fee = 444.0 |
|---|
| 94 | |
|---|
| 95 | def test_manage_payments(self): |
|---|
| 96 | # Managers can add online payment tickets |
|---|
| 97 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
|---|
| 98 | self.browser.open(self.payments_path) |
|---|
| 99 | self.browser.getLink("Add current session payment ticket").click() |
|---|
| 100 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 101 | self.browser.getControl("Create ticket").click() |
|---|
| 102 | self.assertMatches('...Amount could not be determined...', |
|---|
| 103 | self.browser.contents) |
|---|
| 104 | IWorkflowState(self.student).setState('cleared') |
|---|
| 105 | self.browser.open(self.payments_path + '/addop') |
|---|
| 106 | |
|---|
| 107 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 108 | self.browser.getControl("Create ticket").click() |
|---|
| 109 | self.assertMatches('...Book and pay for accommodation first...', |
|---|
| 110 | self.browser.contents) |
|---|
| 111 | # In KwaraPoly only returning students can create school fee payment |
|---|
| 112 | # without having paid accommodation fee |
|---|
| 113 | |
|---|
| 114 | IWorkflowState(self.student).setState('returning') |
|---|
| 115 | configuration = createObject('waeup.SessionConfiguration') |
|---|
| 116 | configuration.academic_session = 2005 |
|---|
| 117 | self.app['configuration'].addSessionConfiguration(configuration) |
|---|
| 118 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 119 | self.browser.getControl("Create ticket").click() |
|---|
| 120 | self.assertMatches('...ticket created...', |
|---|
| 121 | self.browser.contents) |
|---|
| 122 | ctrl = self.browser.getControl(name='val_id') |
|---|
| 123 | value = ctrl.options[0] |
|---|
| 124 | self.browser.getLink(value).click() |
|---|
| 125 | self.assertMatches('...Amount Authorized...', |
|---|
| 126 | self.browser.contents) |
|---|
| 127 | # Managers can open payment slip |
|---|
| 128 | self.browser.getLink("Download payment slip").click() |
|---|
| 129 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 130 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
|---|
| 131 | # Set ticket paid |
|---|
| 132 | ticket = self.student['payments'].items()[0][1] |
|---|
| 133 | ticket.p_state = 'paid' |
|---|
| 134 | self.browser.open(self.payments_path + '/addop') |
|---|
| 135 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 136 | self.browser.getControl("Create ticket").click() |
|---|
| 137 | self.assertMatches('...This type of payment has already been made...', |
|---|
| 138 | self.browser.contents) |
|---|
| 139 | # Remove all payments so that we can add a school fee payment again |
|---|
| 140 | keys = [i for i in self.student['payments'].keys()] |
|---|
| 141 | for payment in keys: |
|---|
| 142 | del self.student['payments'][payment] |
|---|
| 143 | self.browser.open(self.payments_path + '/addop') |
|---|
| 144 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 145 | self.browser.getControl("Create ticket").click() |
|---|
| 146 | self.assertMatches('...ticket created...', |
|---|
| 147 | self.browser.contents) |
|---|
| 148 | self.browser.open(self.payments_path + '/addop') |
|---|
| 149 | self.browser.getControl(name="form.p_category").value = ['carryover1'] |
|---|
| 150 | self.browser.getControl("Create ticket").click() |
|---|
| 151 | self.assertMatches('...ticket created...', |
|---|
| 152 | self.browser.contents) |
|---|
| 153 | self.browser.open(self.payments_path + '/addop') |
|---|
| 154 | self.browser.getControl(name="form.p_category").value = ['carryover2'] |
|---|
| 155 | self.browser.getControl("Create ticket").click() |
|---|
| 156 | self.assertMatches('...ticket created...', |
|---|
| 157 | self.browser.contents) |
|---|
| 158 | self.browser.open(self.payments_path + '/addop') |
|---|
| 159 | self.browser.getControl(name="form.p_category").value = ['carryover3'] |
|---|
| 160 | self.browser.getControl("Create ticket").click() |
|---|
| 161 | self.assertMatches('...ticket created...', |
|---|
| 162 | self.browser.contents) |
|---|
| 163 | self.browser.open(self.payments_path + '/addop') |
|---|
| 164 | self.browser.getControl( |
|---|
| 165 | name="form.p_category").value = ['hostel_maintenance'] |
|---|
| 166 | self.browser.getControl("Create ticket").click() |
|---|
| 167 | self.assertMatches('...ticket created...', |
|---|
| 168 | self.browser.contents) |
|---|
| 169 | self.browser.open(self.payments_path + '/addop') |
|---|
| 170 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 171 | self.browser.getControl("Create ticket").click() |
|---|
| 172 | self.assertMatches('...ticket created...', |
|---|
| 173 | self.browser.contents) |
|---|
| 174 | # In state admitted school fee can't be determined |
|---|
| 175 | IWorkflowState(self.student).setState('admitted') |
|---|
| 176 | self.browser.open(self.payments_path + '/addop') |
|---|
| 177 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 178 | self.browser.getControl("Create ticket").click() |
|---|
| 179 | self.assertMatches('...Amount could not be determined...', |
|---|
| 180 | self.browser.contents) |
|---|
| 181 | self.browser.open(self.payments_path + '/addop') |
|---|
| 182 | self.browser.getControl(name="form.p_category").value = ['certificate'] |
|---|
| 183 | self.browser.getControl("Create ticket").click() |
|---|
| 184 | self.assertMatches('...ticket created...', |
|---|
| 185 | self.browser.contents) |
|---|
| 186 | |
|---|
| 187 | def test_student_payments(self): |
|---|
| 188 | # Login |
|---|
| 189 | IWorkflowState(self.student).setState('returning') |
|---|
| 190 | self.browser.open(self.login_path) |
|---|
| 191 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 192 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 193 | self.browser.getControl("Login").click() |
|---|
| 194 | self.browser.open(self.student_path + '/payments') |
|---|
| 195 | self.assertTrue( |
|---|
| 196 | 'Add current session payment ticket' in self.browser.contents) |
|---|
| 197 | self.assertFalse( |
|---|
| 198 | 'Add previous session payment ticket' in self.browser.contents) |
|---|
| 199 | return |
|---|
| 200 | |
|---|
| 201 | def test_get_returning_data(self): |
|---|
| 202 | # Student is in level 100, session 2004 with verdict A |
|---|
| 203 | utils = getUtility(IStudentsUtils) |
|---|
| 204 | self.assertEqual(utils.getReturningData(self.student),(2005, 200)) |
|---|
| 205 | self.student['studycourse'].current_verdict = 'C' |
|---|
| 206 | self.assertEqual(utils.getReturningData(self.student),(2005, 110)) |
|---|
| 207 | self.student['studycourse'].current_verdict = 'D' |
|---|
| 208 | self.assertEqual(utils.getReturningData(self.student),(2005, 100)) |
|---|
| 209 | return |
|---|
| 210 | |
|---|
| 211 | def test_set_payment_details(self): |
|---|
| 212 | utils = getUtility(IStudentsUtils) |
|---|
| 213 | |
|---|
| 214 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
|---|
| 215 | self.assertEqual(payment, None) |
|---|
| 216 | self.assertEqual(error, u'Amount could not be determined.') |
|---|
| 217 | |
|---|
| 218 | IWorkflowState(self.student).setState('cleared') |
|---|
| 219 | self.assertEqual(local_nonlocal(self.student), 'non-local') |
|---|
| 220 | self.assertEqual(arts_science(self.student), 'science') |
|---|
| 221 | self.assertEqual(we_ft(self.student), 'ft') |
|---|
| 222 | |
|---|
| 223 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
|---|
| 224 | self.assertEqual(error, |
|---|
| 225 | 'Book and pay for accommodation first before making' |
|---|
| 226 | ' school fee payments.') |
|---|
| 227 | # We add a fake maint. payment ticket to meet the condition |
|---|
| 228 | maint_payment = createObject('waeup.StudentOnlinePayment') |
|---|
| 229 | self.student['payments']['any_key'] = maint_payment |
|---|
| 230 | maint_payment.p_category = 'hostel_maintenance' |
|---|
| 231 | maint_payment.p_state = 'paid' |
|---|
| 232 | maint_payment.p_session = 2004 |
|---|
| 233 | |
|---|
| 234 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
|---|
| 235 | self.assertEqual(payment.p_level, 100) |
|---|
| 236 | self.assertEqual(payment.p_session, 2004) |
|---|
| 237 | self.assertEqual(payment.amount_auth, 75500.0) |
|---|
| 238 | self.assertEqual(payment.p_item, u'CERT1') |
|---|
| 239 | self.assertEqual(error, None) |
|---|
| 240 | |
|---|
| 241 | IWorkflowState(self.student).setState('returning') |
|---|
| 242 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
|---|
| 243 | self.assertEqual('Session configuration object is not available.', error) |
|---|
| 244 | configuration = createObject('waeup.SessionConfiguration') |
|---|
| 245 | configuration.academic_session = 2005 |
|---|
| 246 | self.app['configuration'].addSessionConfiguration(configuration) |
|---|
| 247 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
|---|
| 248 | self.assertEqual(payment.p_level, 200) |
|---|
| 249 | self.assertEqual(payment.p_session, 2005) |
|---|
| 250 | self.assertEqual(payment.amount_auth, 35090.0) |
|---|
| 251 | self.assertEqual(payment.p_item, u'CERT1') |
|---|
| 252 | self.assertEqual(error, None) |
|---|
| 253 | |
|---|
| 254 | configuration.penalty_ug = 5000.0 |
|---|
| 255 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
|---|
| 256 | self.assertEqual(payment.amount_auth, 40090.0) |
|---|
| 257 | self.assertEqual(error, None) |
|---|
| 258 | |
|---|
| 259 | error, payment = utils.setPaymentDetails('clearance',self.student) |
|---|
| 260 | self.assertEqual(payment.p_level, 100) |
|---|
| 261 | self.assertEqual(payment.p_session, 2004) |
|---|
| 262 | self.assertEqual(payment.amount_auth, 120.0) |
|---|
| 263 | self.assertEqual(payment.p_item, u'CERT1') |
|---|
| 264 | self.assertEqual(error, None) |
|---|
| 265 | |
|---|
| 266 | error, payment = utils.setPaymentDetails('carryover1',self.student) |
|---|
| 267 | self.assertEqual(payment.p_level, 100) |
|---|
| 268 | self.assertEqual(payment.p_session, 2004) |
|---|
| 269 | self.assertEqual(payment.amount_auth, 6000.0) |
|---|
| 270 | self.assertEqual(payment.p_item, u'One Carry-Over') |
|---|
| 271 | self.assertEqual(payment.p_category, 'carryover1') |
|---|
| 272 | self.assertEqual(error, None) |
|---|
| 273 | |
|---|
| 274 | error, payment = utils.setPaymentDetails('carryover2',self.student) |
|---|
| 275 | self.assertEqual(payment.p_level, 100) |
|---|
| 276 | self.assertEqual(payment.p_session, 2004) |
|---|
| 277 | self.assertEqual(payment.amount_auth, 10000.0) |
|---|
| 278 | self.assertEqual(payment.p_item, u'Two Carry-Overs') |
|---|
| 279 | self.assertEqual(payment.p_category, 'carryover2') |
|---|
| 280 | self.assertEqual(error, None) |
|---|
| 281 | |
|---|
| 282 | error, payment = utils.setPaymentDetails('carryover3',self.student) |
|---|
| 283 | self.assertEqual(payment.p_level, 100) |
|---|
| 284 | self.assertEqual(payment.p_session, 2004) |
|---|
| 285 | self.assertEqual(payment.amount_auth, 15000.0) |
|---|
| 286 | self.assertEqual(payment.p_item, u'Three Carry-Overs') |
|---|
| 287 | self.assertEqual(payment.p_category, 'carryover3') |
|---|
| 288 | self.assertEqual(error, None) |
|---|
| 289 | |
|---|
| 290 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
|---|
| 291 | self.assertEqual(payment.p_level, 100) |
|---|
| 292 | self.assertEqual(payment.p_session, 2004) |
|---|
| 293 | self.assertEqual(payment.amount_auth, 876.0) |
|---|
| 294 | self.assertEqual(payment.p_item, u'My bed coordinates') |
|---|
| 295 | self.assertEqual(error, None) |
|---|
| 296 | |
|---|
| 297 | self.app['hostels']['hall-1'].maint_fee = 0.0 |
|---|
| 298 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
|---|
| 299 | self.assertEqual(payment.p_level, 100) |
|---|
| 300 | self.assertEqual(payment.p_session, 2004) |
|---|
| 301 | self.assertEqual(payment.amount_auth, 180.0) |
|---|
| 302 | self.assertEqual(payment.p_item, u'My bed coordinates') |
|---|
| 303 | self.assertEqual(error, None) |
|---|
| 304 | |
|---|
| 305 | error, payment = utils.setPaymentDetails('bed_allocation',self.student) |
|---|
| 306 | self.assertEqual(payment.p_level, 100) |
|---|
| 307 | self.assertEqual(payment.p_session, 2004) |
|---|
| 308 | self.assertEqual(payment.amount_auth, 150.0) |
|---|
| 309 | self.assertEqual(payment.p_item, u'') |
|---|
| 310 | self.assertEqual(error, None) |
|---|
| 311 | |
|---|
| 312 | error, payment = utils.setPaymentDetails('certificate',self.student) |
|---|
| 313 | self.assertEqual(payment.p_level, 100) |
|---|
| 314 | self.assertEqual(payment.p_session, 2004) |
|---|
| 315 | self.assertEqual(payment.amount_auth, 444.0) |
|---|
| 316 | self.assertEqual(payment.p_item, u'') |
|---|
| 317 | self.assertEqual(payment.p_category, 'certificate') |
|---|
| 318 | self.assertEqual(error, None) |
|---|
| 319 | |
|---|
| 320 | error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100) |
|---|
| 321 | self.assertEqual(error, u'Previous session payment not yet implemented.') |
|---|
| 322 | return |
|---|
| 323 | |
|---|
| 324 | def test_student_start_clearance(self): |
|---|
| 325 | self.browser.open(self.login_path) |
|---|
| 326 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 327 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 328 | self.browser.getControl("Login").click() |
|---|
| 329 | |
|---|
| 330 | IWorkflowInfo(self.student).fireTransition('admit') |
|---|
| 331 | self.browser.open(self.student_path + '/change_portrait') |
|---|
| 332 | image = open(SAMPLE_IMAGE, 'rb') |
|---|
| 333 | ctrl = self.browser.getControl(name='passportuploadedit') |
|---|
| 334 | file_ctrl = ctrl.mech_control |
|---|
| 335 | file_ctrl.add_file(image, filename='my_photo.jpg') |
|---|
| 336 | self.browser.getControl( |
|---|
| 337 | name='upload_passportuploadedit').click() |
|---|
| 338 | self.browser.open(self.student_path + '/start_clearance') |
|---|
| 339 | # In KwaraPoly the students can just start clearance without entering |
|---|
| 340 | # an activation code. |
|---|
| 341 | # Deactivated on 19/10/2016 |
|---|
| 342 | #self.browser.getControl("Start clearance now").click() |
|---|
| 343 | #self.assertMatches('...Clearance process has been started...', |
|---|
| 344 | # self.browser.contents) |
|---|
| 345 | |
|---|
| 346 | def test_change_passport(self): |
|---|
| 347 | self.browser.open(self.login_path) |
|---|
| 348 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 349 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 350 | self.browser.getControl("Login").click() |
|---|
| 351 | |
|---|
| 352 | IWorkflowState(self.student).setState('cleared') |
|---|
| 353 | self.browser.open(self.student_path + '/change_portrait') |
|---|
| 354 | image = open(SAMPLE_IMAGE, 'rb') |
|---|
| 355 | ctrl = self.browser.getControl(name='passportuploadedit') |
|---|
| 356 | file_ctrl = ctrl.mech_control |
|---|
| 357 | file_ctrl.add_file(image, filename='my_photo.jpg') |
|---|
| 358 | self.browser.getControl( |
|---|
| 359 | name='upload_passportuploadedit').click() |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | def test_student_accommodation(self): |
|---|
| 363 | del self.student['accommodation']['2004'] |
|---|
| 364 | # Login |
|---|
| 365 | self.browser.open(self.login_path) |
|---|
| 366 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 367 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 368 | self.browser.getControl("Login").click() |
|---|
| 369 | |
|---|
| 370 | # Students can book accommodation without AC ... |
|---|
| 371 | self.browser.open(self.acco_path) |
|---|
| 372 | IWorkflowInfo(self.student).fireTransition('admit') |
|---|
| 373 | self.browser.getControl("Book accommodation").click() |
|---|
| 374 | self.assertFalse('Activation Code:' in self.browser.contents) |
|---|
| 375 | self.browser.getControl("Create bed ticket").click() |
|---|
| 376 | # Bed is randomly selected but, since there is only |
|---|
| 377 | # one bed for this student, we know that |
|---|
| 378 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
|---|
| 379 | self.browser.contents) |
|---|
| 380 | return |
|---|
| 381 | |
|---|
| 382 | def test_no_beds_for_iot(self): |
|---|
| 383 | self.app['faculties']['fac1'].code = 'IOT' |
|---|
| 384 | del self.student['accommodation']['2004'] |
|---|
| 385 | # Login |
|---|
| 386 | self.browser.open(self.login_path) |
|---|
| 387 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 388 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 389 | self.browser.getControl("Login").click() |
|---|
| 390 | |
|---|
| 391 | self.browser.open(self.acco_path) |
|---|
| 392 | IWorkflowInfo(self.student).fireTransition('admit') |
|---|
| 393 | self.browser.getControl("Book accommodation").click() |
|---|
| 394 | self.browser.getControl("Create bed ticket").click() |
|---|
| 395 | self.assertTrue('There is no free bed in your category iot_male_fr.' in |
|---|
| 396 | self.browser.contents) |
|---|
| 397 | return |
|---|
| 398 | |
|---|
| 399 | def test_admission_pdf_slips(self): |
|---|
| 400 | # Login |
|---|
| 401 | self.browser.open(self.login_path) |
|---|
| 402 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 403 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 404 | self.browser.getControl("Login").click() |
|---|
| 405 | # admission slip |
|---|
| 406 | IWorkflowState(self.student).setState('school fee paid') |
|---|
| 407 | self.browser.open(self.student_path) |
|---|
| 408 | self.browser.getLink("Download admission letter").click() |
|---|
| 409 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 410 | self.assertEqual(self.browser.headers['Content-Type'], |
|---|
| 411 | 'application/pdf') |
|---|
| 412 | path = os.path.join(samples_dir(), 'admission_slip.pdf') |
|---|
| 413 | open(path, 'wb').write(self.browser.contents) |
|---|
| 414 | print "Sample PDF admission_slip_slip.pdf written to %s" % path |
|---|
| 415 | self.browser.open(self.student_path) |
|---|
| 416 | self.assertRaises( |
|---|
| 417 | LinkNotFoundError, self.browser.getLink, 'Download admission notification') |
|---|
| 418 | self.browser.open(self.student_path + '/admission_notification.pdf') |
|---|
| 419 | self.assertTrue('Not allowed' in self.browser.contents) |
|---|
| 420 | # admission notification |
|---|
| 421 | IWorkflowState(self.student).setState('cleared') |
|---|
| 422 | self.browser.open(self.student_path) |
|---|
| 423 | self.browser.getLink("Download admission notification").click() |
|---|
| 424 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 425 | self.assertEqual(self.browser.headers['Content-Type'], |
|---|
| 426 | 'application/pdf') |
|---|
| 427 | path = os.path.join(samples_dir(), 'admission_notification.pdf') |
|---|
| 428 | open(path, 'wb').write(self.browser.contents) |
|---|
| 429 | print "Sample PDF admission_notification.pdf written to %s" % path |
|---|
| 430 | self.browser.open(self.student_path) |
|---|
| 431 | self.assertRaises( |
|---|
| 432 | LinkNotFoundError, self.browser.getLink, 'Download admission letter') |
|---|
| 433 | self.browser.open(self.student_path + '/admission_slip.pdf') |
|---|
| 434 | self.assertTrue('Not allowed' in self.browser.contents) |
|---|
| 435 | return |
|---|
| 436 | |
|---|
| 437 | def test_registration_pdf_slips(self): |
|---|
| 438 | # Student cant login if their password is not set |
|---|
| 439 | IWorkflowState(self.student).setState('school fee paid') |
|---|
| 440 | self.browser.open(self.login_path) |
|---|
| 441 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 442 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 443 | self.browser.getControl("Login").click() |
|---|
| 444 | self.browser.getLink("Course of Study").click() |
|---|
| 445 | self.browser.getLink("Add course list").click() |
|---|
| 446 | self.assertMatches('...Add current level 100 (Year 1)...', |
|---|
| 447 | self.browser.contents) |
|---|
| 448 | self.browser.getControl("Create course list now").click() |
|---|
| 449 | # A level with one course ticket was created |
|---|
| 450 | self.browser.getLink("100").click() |
|---|
| 451 | self.browser.getLink("Download course profile slip").click() |
|---|
| 452 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 453 | self.assertEqual(self.browser.headers['Content-Type'], |
|---|
| 454 | 'application/pdf') |
|---|
| 455 | path = os.path.join(samples_dir(), 'course_registration_slip.pdf') |
|---|
| 456 | open(path, 'wb').write(self.browser.contents) |
|---|
| 457 | print "Sample PDF course_registration_slip.pdf written to %s" % path |
|---|
| 458 | |
|---|
| 459 | self.browser.open(self.student_path) |
|---|
| 460 | self.browser.getLink("Download registration form").click() |
|---|
| 461 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 462 | self.assertEqual(self.browser.headers['Content-Type'], |
|---|
| 463 | 'application/pdf') |
|---|
| 464 | path = os.path.join(samples_dir(), 'registration_slip.pdf') |
|---|
| 465 | open(path, 'wb').write(self.browser.contents) |
|---|
| 466 | print "Sample PDF registration_form.pdf written to %s" % path |
|---|
| 467 | |
|---|
| 468 | return |
|---|
| 469 | |
|---|
| 470 | def test_payment_disabled(self): |
|---|
| 471 | IWorkflowState(self.student).setState('returning') |
|---|
| 472 | configuration = createObject('waeup.SessionConfiguration') |
|---|
| 473 | configuration.academic_session = 2005 |
|---|
| 474 | self.app['configuration'].addSessionConfiguration(configuration) |
|---|
| 475 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
|---|
| 476 | self.browser.open(self.payments_path) |
|---|
| 477 | self.browser.getLink("Add current session payment ticket").click() |
|---|
| 478 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 479 | self.browser.getControl("Create ticket").click() |
|---|
| 480 | self.assertMatches('...ticket created...', |
|---|
| 481 | self.browser.contents) |
|---|
| 482 | self.app['configuration']['2005'].payment_disabled = ['sf_all'] |
|---|
| 483 | self.browser.getLink("Add current session payment ticket").click() |
|---|
| 484 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 485 | self.browser.getControl("Create ticket").click() |
|---|
| 486 | self.assertMatches('...This category of payments has been disabled...', |
|---|
| 487 | self.browser.contents) |
|---|
| 488 | self.app['configuration']['2005'].payment_disabled = ['sf_non_pg'] |
|---|
| 489 | # Non-PG students can't pay ... |
|---|
| 490 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 491 | self.browser.getControl("Create ticket").click() |
|---|
| 492 | self.assertMatches('...This category of payments has been disabled...', |
|---|
| 493 | self.browser.contents) |
|---|
| 494 | # ... but PG can pay. |
|---|
| 495 | self.certificate.study_mode = 'pg_ft' |
|---|
| 496 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
|---|
| 497 | self.browser.getControl("Create ticket").click() |
|---|
| 498 | self.assertMatches('...ticket created...', |
|---|
| 499 | self.browser.contents) |
|---|
| 500 | return |
|---|
| 501 | |
|---|
| 502 | def test_student_course_registration(self): |
|---|
| 503 | # Student cant login if their password is not set |
|---|
| 504 | IWorkflowState(self.student).setState('school fee paid') |
|---|
| 505 | self.student['studycourse'].current_level = 200 |
|---|
| 506 | self.browser.open(self.login_path) |
|---|
| 507 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 508 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 509 | self.browser.getControl("Login").click() |
|---|
| 510 | self.browser.open(self.student_path + '/studycourse/add') |
|---|
| 511 | # Now students can add the current study level |
|---|
| 512 | self.assertMatches('...Add current level 200 (Year 2)...', |
|---|
| 513 | self.browser.contents) |
|---|
| 514 | self.browser.getControl("Create course list now").click() |
|---|
| 515 | self.browser.getLink("200").click() |
|---|
| 516 | self.browser.getLink("Edit course list").click() |
|---|
| 517 | self.browser.getLink("here").click() |
|---|
| 518 | self.browser.getControl(name="form.course").value = ['COURSE1'] |
|---|
| 519 | self.course.credits = 100000 |
|---|
| 520 | self.browser.getControl("Add course ticket").click() |
|---|
| 521 | self.assertFalse( |
|---|
| 522 | 'Total credits exceed ' in self.browser.contents) |
|---|
| 523 | self.browser.getControl("Register course list").click() |
|---|
| 524 | self.assertTrue( |
|---|
| 525 | 'Course list has been registered' in self.browser.contents) |
|---|
| 526 | self.assertEqual(self.student.state, 'courses registered') |
|---|
| 527 | return |
|---|
| 528 | |
|---|
| 529 | def test_set_matric_number(self): |
|---|
| 530 | # Login as student |
|---|
| 531 | self.browser.open(self.login_path) |
|---|
| 532 | IWorkflowState(self.student).setState('school fee paid') |
|---|
| 533 | self.browser.open(self.login_path) |
|---|
| 534 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 535 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 536 | self.browser.getControl("Login").click() |
|---|
| 537 | self.assertRaises( |
|---|
| 538 | LinkNotFoundError, |
|---|
| 539 | self.browser.getLink, 'Get Matriculation Number') |
|---|
| 540 | self.student.matric_number = None |
|---|
| 541 | self.student['studycourse'].entry_mode = 'nd_ft' |
|---|
| 542 | self.student['studycourse'].entry_session = 2014 |
|---|
| 543 | self.browser.open(self.student_path) |
|---|
| 544 | self.assertRaises( |
|---|
| 545 | LinkNotFoundError, |
|---|
| 546 | self.browser.getLink, 'Get Matriculation Number') |
|---|
| 547 | self.student['studycourse'].entry_session = 2015 |
|---|
| 548 | self.browser.open(self.student_path) |
|---|
| 549 | self.browser.getLink("Get Matriculation Number").click() |
|---|
| 550 | self.assertTrue('Matriculation number ND/15/dep1/FT/001 assigned.' |
|---|
| 551 | in self.browser.contents) |
|---|
| 552 | self.assertEqual(self.student.matric_number, 'ND/15/dep1/FT/001') |
|---|
| 553 | self.assertRaises( |
|---|
| 554 | LinkNotFoundError, |
|---|
| 555 | self.browser.getLink, 'Get Matriculation Number') |
|---|
| 556 | # Setting matric number is logged. |
|---|
| 557 | logfile = os.path.join( |
|---|
| 558 | self.app['datacenter'].storage, 'logs', 'students.log') |
|---|
| 559 | logcontent = open(logfile).read() |
|---|
| 560 | self.assertTrue('W1000000 - waeup.kwarapoly.students.browser.StudentGetMatricNumberView - ' |
|---|
| 561 | 'W1000000 - ND/15/dep1/FT/001 assigned' in logcontent) |
|---|
| 562 | return |
|---|
| 563 | |
|---|
| 564 | # deactivated on 5/11/15, see ticket 129 |
|---|
| 565 | def xxx_test_student_fileupload(self): |
|---|
| 566 | # Students can edit clearance data |
|---|
| 567 | IWorkflowState(self.student).setState('clearance started') |
|---|
| 568 | self.browser.open(self.login_path) |
|---|
| 569 | self.browser.getControl(name="form.login").value = self.student_id |
|---|
| 570 | self.browser.getControl(name="form.password").value = 'spwd' |
|---|
| 571 | self.browser.getControl("Login").click() |
|---|
| 572 | self.browser.getLink("Clearance Data").click() |
|---|
| 573 | self.browser.getLink("Edit").click() |
|---|
| 574 | self.browser.getControl("Save and request clearance").click() |
|---|
| 575 | self.assertMatches('...Required input is missing...', |
|---|
| 576 | self.browser.contents) |
|---|
| 577 | self.student.nationality = u'DE' |
|---|
| 578 | self.browser.open(self.edit_clearance_path) |
|---|
| 579 | self.browser.getControl("Save and request clearance").click() |
|---|
| 580 | self.assertTrue( |
|---|
| 581 | 'Missing: Birth Certificate, Acceptance Letter, LGA Identification, ' |
|---|
| 582 | 'First Sitting Result, Result Statement, Guarantor/Referee Letter, ' |
|---|
| 583 | 'Affidavit of Good Conduct' |
|---|
| 584 | in self.browser.contents) |
|---|
| 585 | # Students can upload documents |
|---|
| 586 | ctrl = self.browser.getControl(name='birthcertificateupload') |
|---|
| 587 | file_obj = open(SAMPLE_IMAGE, 'rb') |
|---|
| 588 | file_ctrl = ctrl.mech_control |
|---|
| 589 | file_ctrl.add_file(file_obj, filename='my_birth_certificate.jpg') |
|---|
| 590 | self.browser.getControl( |
|---|
| 591 | name='upload_birthcertificateupload').click() |
|---|
| 592 | self.assertTrue( |
|---|
| 593 | 'href="http://localhost/app/students/W1000000/birth_certificate"' |
|---|
| 594 | in self.browser.contents) |
|---|
| 595 | # The list of missing files is now slightly shorter |
|---|
| 596 | self.browser.getControl("Save and request clearance").click() |
|---|
| 597 | self.assertTrue( |
|---|
| 598 | 'Missing: Acceptance Letter, LGA Identification, ' |
|---|
| 599 | 'First Sitting Result, Result Statement, Guarantor/Referee Letter, ' |
|---|
| 600 | 'Affidavit of Good Conduct' |
|---|
| 601 | in self.browser.contents) |
|---|
| 602 | return |
|---|