Ignore:
Timestamp:
4 Apr 2013, 10:38:36 (12 years ago)
Author:
Henrik Bettermann
Message:

Add method to revert a previously made transfer.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

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

    r9962 r10054  
    257257        return
    258258
     259    def revert_transfer(self):
     260        """ Revert previous transfer.
     261
     262        """
     263        if not self.has_key('studycourse_1'):
     264            return -1
     265        del self['studycourse']
     266        if 'studycourse_2' in self.keys():
     267            studycourse = self['studycourse_2']
     268            self['studycourse'] = studycourse
     269            del self['studycourse_2']
     270        else:
     271            studycourse = self['studycourse_1']
     272            self['studycourse'] = studycourse
     273            del self['studycourse_1']
     274        self.__parent__.logger.info(
     275            '%s - transfer reverted' % self.student_id)
     276        history = IObjectHistory(self)
     277        history.addMessage('Transfer reverted')
     278        return
    259279
    260280# Set all attributes of Student required in IStudent as field
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py

    r9138 r10054  
    319319        self.assertEqual(len(results), 1)
    320320        assert results[0] is self.app['students'][self.student.student_id]
     321
     322        # Previous transfer can be successively reverted.
     323        self.assertEqual(self.student['studycourse_2'].certificate.code, 'CERT2')
     324        self.assertEqual(self.student['studycourse_1'].certificate.code, 'CERT1')
     325        self.assertEqual(self.student['studycourse'].certificate.code, 'CERT1')
     326        error = self.student.revert_transfer()
     327        self.assertTrue(error == None)
     328        self.assertEqual([i for i in self.student.keys()],
     329            [u'accommodation', u'payments', u'studycourse',
     330             u'studycourse_1'])
     331        self.assertEqual(self.student['studycourse_1'].certificate.code, 'CERT1')
     332        self.assertEqual(self.student['studycourse'].certificate.code, 'CERT2')
     333        # The students_catalog has been updated again.
     334        cat = queryUtility(ICatalog, name='students_catalog')
     335        results = cat.searchResults(certcode=('CERT2', 'CERT2'))
     336        results = [x for x in results]
     337        self.assertEqual(len(results), 1)
     338        assert results[0] is self.app['students'][self.student.student_id]
     339        error = self.student.revert_transfer()
     340        self.assertTrue(error == None)
     341        self.assertEqual([i for i in self.student.keys()],
     342            [u'accommodation', u'payments', u'studycourse'])
     343        self.assertEqual(self.student['studycourse'].certificate.code, 'CERT1')
     344        error = self.student.revert_transfer()
     345        self.assertTrue(error == -1)
     346        # The students_catalog has been updated again.
     347        cat = queryUtility(ICatalog, name='students_catalog')
     348        results = cat.searchResults(certcode=('CERT1', 'CERT1'))
     349        results = [x for x in results]
     350        self.assertEqual(len(results), 1)
     351        assert results[0] is self.app['students'][self.student.student_id]
     352        results = cat.searchResults(certcode=('CERT2', 'CERT2'))
     353        results = [x for x in results]
     354        self.assertEqual(len(results), 0)
     355        logcontent = open(logfile).read()
     356        self.assertTrue('system - K1000000 - transfer reverted'
     357            in logcontent)
     358        messages = ' '.join(self.student.history.messages)
     359        self.assertTrue('Transfer reverted by system' in messages)
    321360        return
    322361
Note: See TracChangeset for help on using the changeset viewer.