Changeset 13991


Ignore:
Timestamp:
25 Jun 2016, 08:26:16 (9 years ago)
Author:
Henrik Bettermann
Message:

Improve RefereeReportAddFormPage? and add tests.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r13976 r13991  
    15111511    """
    15121512    grok.context(IApplicant)
    1513     grok.require('waeup.manageApplication') # XXX: Will be public
     1513    grok.require('waeup.Public')
    15141514    grok.name('addrefereereport')
    15151515    form_fields = grok.AutoFields(
     
    15201520
    15211521    def update(self):
    1522         # XXX: Check mandate
     1522        blocker = grok.getSite()['configuration'].maintmode_enabled_by
     1523        if blocker:
     1524            self.flash(_('The portal is in maintenance mode. '
     1525                        'Referee report forms are temporarily disabled.'),
     1526                       type='warning')
     1527            self.redirect(self.application_url())
     1528            return
     1529        # Check mandate
     1530        form = self.request.form
     1531        mandate_id = form.get('mandate_id', None)
     1532        mandates = grok.getSite()['mandates']
     1533        mandate = mandates.get(mandate_id, None)
     1534        if mandate is None and not self.request.form.get('form.actions.submit'):
     1535            self.flash(_('No mandate.'), type='warning')
     1536            self.redirect(self.application_url())
     1537            return
     1538        if mandate:
     1539            # Prefill form with mandate params
     1540            self.form_fields.get(
     1541                'name').field.default = mandate.params['name']
     1542            self.form_fields.get(
     1543                'email').field.default = mandate.params['email']
    15231544        super(RefereeReportAddFormPage, self).update()
    15241545        return
     
    15351556        self.applyData(report, **data)
    15361557        self.context[report.r_id] = report
    1537         self.flash(_('Referee report created.'))
     1558        self.flash(_('Referee report has been saved. Thank you!'))
    15381559        self.context.writeLogMessage(self, 'added: %s' % report.r_id)
    1539         # XXX: Email has to be sent.
    1540         # XXX: Will be replaced by landing page
    1541         self.redirect(
    1542             self.url(self.context[report.r_id], 'index'))
    1543         return
     1560        # XXX: Delete mandate
     1561        # XXX: Send email
     1562        self.redirect(self.application_url())
     1563        return
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r13976 r13991  
    4747from waeup.kofa.university.faculty import Faculty
    4848from waeup.kofa.university.department import Department
     49from waeup.kofa.mandates.mandate import RefereeReportMandate
    4950from waeup.kofa.tests.test_async import FunctionalAsyncTestCase
    5051
     
    15251526    layer = FunctionalLayer
    15261527
     1528    def test_refereereport_mandate(self):
     1529        mandate = RefereeReportMandate()
     1530        mandate.params['name'] = u'John Referee'
     1531        mandate.params['email'] = 'aa@aa.aa'
     1532        mandate.params[
     1533            'redirect_path'] = '/applicants/%s/%s/addrefereereport' % (
     1534                container_name_1, self.applicant.application_number)
     1535        self.app['mandates'].addMandate(mandate)
     1536        # Let's open the add form page via the mandate view
     1537        self.browser.open('http://localhost/app/mandate?mandate_id=%s'
     1538            % mandate.mandate_id)
     1539        # Form page opens and is prefilled
     1540        self.assertEqual(
     1541            self.browser.url,
     1542            'http://localhost/app/applicants/%s/%s/addrefereereport?mandate_id=%s'
     1543            % (container_name_1, self.applicant.application_number,
     1544            mandate.mandate_id))
     1545        self.assertTrue('value="John Referee"' in self.browser.contents)
     1546        # Let's open the page directly with an invalid mandate
     1547        self.browser.open(
     1548            'http://localhost/app/applicants/%s/%s/addrefereereport?mandate_id=wrongmadate'
     1549            % (container_name_1, self.applicant.application_number))
     1550        self.assertTrue('<div class="alert alert-warning">No mandate.</div>'
     1551            in self.browser.contents)
     1552        self.assertEqual(self.browser.url, 'http://localhost/app')
     1553        # Page is also blocked in maintenance mode
     1554        grok.getSite()['configuration'].maintmode_enabled_by = u'anybody'
     1555        self.browser.open(
     1556            'http://localhost/app/applicants/%s/%s/addrefereereport?mandate_id=%s'
     1557            % (container_name_1, self.applicant.application_number,
     1558            mandate.mandate_id))
     1559        self.assertTrue('<div class="alert alert-warning">The portal is '
     1560                        'in maintenance mode'
     1561            in self.browser.contents)
     1562        self.assertEqual(self.browser.url, 'http://localhost/app')
     1563
    15271564    def test_add_and_view_reports(self):
    1528         # Managers can view reports
    1529         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1530         self.browser.open(self.manage_path)
    1531         # So far no report has been added
    1532         self.assertFalse('Referee' in self.browser.contents)
    1533         # XXX: Form will be public
    1534         self.browser.open(self.view_path + '/addrefereereport')
    1535         self.browser.getControl(name="form.name").value = 'John Trust'
    1536         self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     1565        mandate = RefereeReportMandate()
     1566        mandate.params['name'] = u'John Referee'
     1567        mandate.params['email'] = 'aa@aa.aa'
     1568        mandate.params[
     1569            'redirect_path'] = '/applicants/%s/%s/addrefereereport' % (
     1570                container_name_1, self.applicant.application_number)
     1571        self.app['mandates'].addMandate(mandate)
     1572        # Let's open the add form page via the mandate view
     1573        self.browser.open('http://localhost/app/mandate?mandate_id=%s'
     1574            % mandate.mandate_id)
    15371575        self.browser.getControl("Submit").click()
    1538         self.assertTrue('Referee report created' in self.browser.contents)
    1539         # Report has been created and we are viewing the report's index page
     1576        self.assertTrue('Referee report has been saved' in self.browser.contents)
     1577        self.assertEqual(self.browser.url, 'http://localhost/app')
     1578        # Report has been created
    15401579        self.assertEqual(len(self.applicant.refereereports), 1)
    15411580        report = self.applicant.refereereports[0]
     1581        # Managers can view the report
     1582        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1583        self.browser.open(self.manage_path)
     1584        self.browser.getLink("%s" % report.r_id).click()
    15421585        self.assertEqual(
    1543             self.browser.url, self.view_path  + '/%s/index' % report.r_id)
     1586            self.browser.url, self.view_path  + '/%s' % report.r_id)
     1587        self.assertTrue('John Referee' in self.browser.contents)
    15441588        # Report creation is logged
    15451589        logfile = os.path.join(
     
    15471591        logcontent = open(logfile).read()
    15481592        self.assertTrue(
    1549             'zope.mgr - applicants.browser.RefereeReportAddFormPage - '
     1593            'zope.anybody - applicants.browser.RefereeReportAddFormPage - '
    15501594            '%s - added: %s\n' % (self.applicant.applicant_id, report.r_id)
    15511595            in logcontent
Note: See TracChangeset for help on using the changeset viewer.