Ignore:
Timestamp:
24 Jun 2016, 07:14:01 (8 years ago)
Author:
Henrik Bettermann
Message:

Add RefereeReportMandate?

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/mandate.py

    r13987 r13988  
    7979        del self.__parent__[self.mandate_id]
    8080        return msg, redirect_path
     81
     82class RefereeReportMandate(Mandate):
     83    """This is a mandate which can unlock a `RefereeReportAddFormPage`.
     84    The mandate is not automatically deleted. This has to be done
     85    by the submit method of the add form page.
     86    """
     87
     88    def execute(self):
     89        if self.expires < datetime.utcnow():
     90            return _('Mandate expired.'), ''
     91        redirect_path = self.params.get('redirect_path', None)
     92        name = self.params.get('name', None)
     93        email = self.params.get('email', None)
     94        if None in (redirect_path, name, email):
     95            return _('Wrong mandate parameters.'), ''
     96        return None, redirect_path
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py

    r13987 r13988  
    3232    IMandatesContainer, IMandate)
    3333from waeup.kofa.mandates.container import MandatesContainer
    34 from waeup.kofa.mandates.mandate import PasswordMandate
     34from waeup.kofa.mandates.mandate import PasswordMandate, RefereeReportMandate
    3535from waeup.kofa.testing import (FunctionalLayer, FunctionalTestCase)
    3636
     
    191191        self.assertTrue('1 mandate(s) were purged' in self.browser.contents)
    192192        self.assertEqual(self.app['mandates'].count, (1, 0, 1))
    193         return
    194 
    195     def test_browser(self):
     193
     194    def test_browser_set_password(self):
    196195        student = createObject('waeup.Student')
    197196        self.app['students'].addStudent(student)
     
    219218        self.assertTrue('Misuse' in self.browser.contents)
    220219        self.assertEqual(self.browser.url, 'http://localhost/app/')
    221         return
     220
     221    def test_refereereport_mandate(self):
     222        mandate = RefereeReportMandate()
     223        mandate.params['name'] = u'John Referee'
     224        mandate.params['email'] = 'aa@aa.aa'
     225        mandate.params['redirect_path'] = 'applicants/87689'
     226        self.app['mandates'].addMandate(mandate)
     227        (msg, redirect_path) = mandate.execute()
     228        self.assertEqual(msg, None)
     229        self.assertEqual(redirect_path, 'applicants/87689')
     230        # Mandate has not been deleted
     231        self.assertEqual(len(self.app['mandates'].keys()), 1)
     232        mandate.params['redirect_path'] = None
     233        (msg, redirect_path) = mandate.execute()
     234        self.assertEqual(msg, 'Wrong mandate parameters.')
     235        self.assertEqual(redirect_path, '')
     236        # Add and execute an expired mandate
     237        mandate2 = RefereeReportMandate(days=0)
     238        mandate2.params['name'] = u'John Referee'
     239        mandate2.params['email'] = 'aa@aa.aa'
     240        mandate2.params['redirect_path'] = 'applicants/87689'
     241        self.app['mandates'].addMandate(mandate2)
     242        (msg, redirect_path) = mandate2.execute()
     243        self.assertEqual(msg, 'Mandate expired.')
     244        self.assertEqual(redirect_path, '')
     245        # Both mandates still exist
     246        self.assertEqual(len(self.app['mandates'].keys()), 2)
Note: See TracChangeset for help on using the changeset viewer.