Changeset 12904 for main/waeup.kwarapoly/trunk/src/waeup/kwarapoly
- Timestamp:
- 5 May 2015, 12:17:58 (10 years ago)
- Location:
- main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_utils.py
r9614 r12904 1 1 # -*- coding: utf-8 -*- 2 from hurry.workflow.interfaces import IWorkflowState 3 from zope.component import getUtility 2 4 from waeup.kofa.testing import FunctionalTestCase 3 from zope.component import getUtility 5 from waeup.kofa.university.faculty import Faculty 6 from waeup.kofa.university.department import Department 4 7 from waeup.kofa.students.interfaces import IStudentsUtils 5 8 from waeup.kofa.students.tests.test_browser import StudentsFullSetup 6 9 from waeup.kwarapoly.testing import FunctionalLayer 7 10 8 class BedAllocationTests(StudentsFullSetup):11 class StudentsUtilsTests(StudentsFullSetup): 9 12 10 13 layer = FunctionalLayer … … 43 46 self.assertEqual(acc_details['bt'], 'regular_male_fi') 44 47 return 48 49 def test_setMatricNumber(self): 50 utils = getUtility(IStudentsUtils) 51 self.student.matric_number = None 52 msg, mnumber = utils.setMatricNumber(self.student) 53 self.assertEqual(msg, 'Matriculation number cannot be set.') 54 self.assertEqual(mnumber, None) 55 self.student['studycourse'].entry_mode = 'nd_ft' 56 self.student['studycourse'].entry_session = 2013 57 msg, mnumber = utils.setMatricNumber(self.student) 58 self.assertEqual(self.student.matric_number, 'ND/13/dep1/FT/001') 59 self.assertEqual( 60 self.app['faculties']['fac1']['dep1'].next_matric_dict, 61 {2013: 2}) 62 # setting a new matric number in 2014, extends next_matric_dict 63 self.student['studycourse'].entry_session = 2014 64 self.student.matric_number = None 65 msg, mnumber = utils.setMatricNumber(self.student) 66 self.assertEqual( 67 self.app['faculties']['fac1']['dep1'].next_matric_dict, 68 {2013: 2, 2014: 2}) 69 # setting a new matric number in 2014 again, increases the counter 70 self.student.matric_number = None 71 msg, mnumber = utils.setMatricNumber(self.student) 72 self.assertEqual( 73 self.app['faculties']['fac1']['dep1'].next_matric_dict, 74 {2013: 2, 2014: 3}) 75 # matric number must not exist 76 msg, mnumber = utils.setMatricNumber(self.student) 77 self.assertEqual(msg, 'Matriculation number already set.') 78 # certificate must be set. 79 self.student.matric_number = None 80 self.student['studycourse'].certificate = None 81 msg, mnumber = utils.setMatricNumber(self.student) 82 self.assertEqual(msg, 'No certificate assigned.') 83 return -
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py
r12148 r12904 319 319 return d 320 320 321 def increaseMatricInteger(self, student): 322 """Increase counter for matric numbers. 323 """ 324 cert = getattr(student.get('studycourse', None), 'certificate', None) 325 entry_session = getattr( 326 student.get('studycourse', None), 'entry_session', None) 327 dep = cert.__parent__.__parent__ 328 next_matric_dict = getattr(dep, 'next_matric_dict', None) 329 if not next_matric_dict: 330 # add next_matric_dict attribute 331 dep.next_matric_dict = {} 332 if not dep.next_matric_dict.get(entry_session, None): 333 # initialize counter element 334 dep.next_matric_dict[entry_session] = 2 335 return 336 # increase counter value of entry_session 337 dep.next_matric_dict[entry_session] += 1 338 return 339 340 def constructMatricNumber(self, student): 341 """Fetch the matric number counter which fits the student and 342 construct the new matric number of the student. 343 344 A typical matriculation number is like this: ND/14/STA/FT/015 345 346 ND = Study Mode Prefix 347 14 = Year of Entry 348 STA = Department Code 349 FT = Study Mode Suffix 350 015 = Serial Number (Every department starts from "001" every 351 session and the numbers build up arithmetically) 352 """ 353 cert = getattr(student.get('studycourse', None), 'certificate', None) 354 entry_session = getattr( 355 student.get('studycourse', None), 'entry_session', None) 356 entry_mode = getattr( 357 student.get('studycourse', None), 'entry_mode', None) 358 if None in (cert, entry_session, entry_mode): 359 return _('Matriculation number cannot be set.'), None 360 try: 361 (prefix, suffix) = entry_mode.split('_') 362 (prefix, suffix) = (prefix.upper(), suffix.upper()) 363 except ValueError: 364 return _('Matriculation number cannot be set.'), None 365 dep = cert.__parent__.__parent__ 366 next_integer = getattr( 367 dep, 'next_matric_dict', {}).get(entry_session, 1) 368 entry_year = entry_session - 100*(entry_session/100) 369 matric_number = "%s/%s/%s/%s/%03d" % ( 370 prefix, entry_year, student.depcode, suffix, next_integer) 371 return None, matric_number 372 321 373 PWCHANGE_STATES = (ADMITTED, CLEARED, RETURNING) 322 374
Note: See TracChangeset for help on using the changeset viewer.