Ignore:
Timestamp:
22 Apr 2014, 07:13:16 (11 years ago)
Author:
Henrik Bettermann
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_utils.py

    r11588 r11589  
    11# -*- coding: utf-8 -*-
    22import unittest
    3 from zope.component import getUtility
     3import grok
     4from zope.component import getUtility, queryUtility, createObject
     5from zope.catalog.interfaces import ICatalog
    46from waeup.kofa.students.interfaces import IStudentsUtils
    57from waeup.kofa.students.utils import formatted_text
     
    3739        # In this case current_level remains unchanged and no error is raised.
    3840        self.assertEqual(self.student['studycourse'].current_level, 600)
     41
     42    def test_setMatricNumber(self):
     43        site = grok.getSite()
     44        utils = getUtility(IStudentsUtils)
     45        msg, mnumber = utils.setMatricNumber(self.student)
     46        self.assertEqual(msg, 'Matriculation number cannot be set.')
     47        self.assertEqual(mnumber, None)
     48        site['configuration'].next_matric_integer = 1
     49        msg, mnumber = utils.setMatricNumber(self.student)
     50        self.assertEqual(msg, 'Matriculation number already set.')
     51        self.assertEqual(mnumber, None)
     52        self.assertEqual(self.student.matric_number, '234')
     53        self.student.matric_number = None
     54        msg, mnumber = utils.setMatricNumber(self.student)
     55        self.assertEqual(msg, None)
     56        self.assertEqual(mnumber, 1)
     57        self.assertEqual(self.student.matric_number, '1')
     58        self.assertEqual(site['configuration'].next_matric_integer, 2)
     59        # Student can be found in catalog.
     60        cat = queryUtility(ICatalog, name='students_catalog')
     61        results = list(cat.searchResults(matric_number=('1', '1')))
     62        self.assertEqual(self.student,results[0])
     63        # Add another student.
     64        another_student = createObject('waeup.Student')
     65        another_student.matric_number = u'2'
     66        self.app['students'].addStudent(another_student)
     67        # Matric number can't be assigned twice.
     68        self.student.matric_number = None
     69        msg, mnumber = utils.setMatricNumber(self.student)
     70        self.assertEqual(msg, 'Matriculation number exists.')
     71        self.assertEqual(mnumber, None)
     72        self.assertEqual(self.student.matric_number, None)
     73        return
     74
Note: See TracChangeset for help on using the changeset viewer.