Ignore:
Timestamp:
4 Jul 2016, 09:02:52 (9 years ago)
Author:
Henrik Bettermann
Message:

Send invitation email to referees when applicant finally submits the form.

File:
1 edited

Legend:

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

    r13992 r14014  
    2424import tempfile
    2525import grok
     26import logging
    2627from datetime import datetime
    2728from StringIO import StringIO
     
    4142from waeup.kofa.payments.interfaces import IPayer
    4243from waeup.kofa.configuration import SessionConfiguration
     44from waeup.kofa.refereeentries import RefereeEntry
    4345from waeup.kofa.applicants.container import ApplicantsContainer
    4446from waeup.kofa.applicants.applicant import Applicant
     
    15261528    layer = FunctionalLayer
    15271529
     1530    def setUp(self):
     1531        super(ApplicantRefereeReportTests, self).setUp()
     1532        self.setup_logging()
     1533        return
     1534
     1535    def tearDown(self):
     1536        super(ApplicantRefereeReportTests, self).tearDown()
     1537        self.teardown_logging()
     1538        return
     1539
     1540    def setup_logging(self):
     1541        # setup a log-handler that catches all fake mailer output
     1542        self.stream = StringIO()
     1543        handler = logging.StreamHandler(self.stream)
     1544        logger = logging.getLogger('test.smtp')
     1545        logger.addHandler(handler)
     1546        logger.setLevel(logging.INFO)
     1547        return
     1548
     1549    def get_fake_smtp_output(self):
     1550        # get output generated by fake mailer
     1551        self.stream.flush()
     1552        self.stream.seek(0)
     1553        return self.stream.read()
     1554
     1555    def teardown_logging(self):
     1556        # remove the log handler for fake mailer output
     1557        logger = logging.getLogger('test.smtp')
     1558        handlers = [x for x in logger.handlers]
     1559        for handler in handlers:
     1560            logger.removeHandler(handler)
     1561        return
     1562
    15281563    def test_refereereport_mandate(self):
    15291564        mandate = RefereeReportMandate()
     
    16041639        # Mandate is deleted
    16051640        self.assertEqual(len(self.app['mandates'].keys()), 0)
     1641
     1642    def test_final_submit_with_referees(self):
     1643        # Add two referees
     1644        referee1 = RefereeEntry()
     1645        referee2 = RefereeEntry()
     1646        referee1.name = u'Linda Tree'
     1647        referee1.email = 'linda@forest.de'
     1648        referee2.name = u'Otis Stone'
     1649        referee2.email = 'otis@stones.de'
     1650        self.applicant.referees = [referee1, referee2]
     1651        self.assertFalse(referee1.email_sent)
     1652        self.assertFalse(referee2.email_sent)
     1653        self.login()
     1654        IWorkflowInfo(self.applicant).fireTransition('pay')
     1655        self.browser.open(self.edit_path)
     1656        self.fill_correct_values() # fill other fields with correct values
     1657        image = open(SAMPLE_IMAGE, 'rb')
     1658        ctrl = self.browser.getControl(name='form.passport')
     1659        file_ctrl = ctrl.mech_control
     1660        file_ctrl.add_file(image, filename='myphoto.jpg')
     1661        self.browser.getControl("Save").click()
     1662        self.browser.getControl(name="confirm_passport").value = True
     1663        self.browser.getControl("Finally Submit").click()
     1664        self.assertEqual(
     1665            [u'Sending email from no-reply@waeup.org to linda@forest.de:',
     1666             u'Message:',
     1667             u'msg: MIME-Version: 1.0',
     1668             u'msg: Content-Type: text/plain; charset="us-ascii"',
     1669             u'msg: Content-Transfer-Encoding: 7bit',
     1670             u'msg: From: Administrator <no-reply@waeup.org>',
     1671             u'msg: To: Linda Tree <linda@forest.de>',
     1672             u'msg: Reply-To: Administrator <contact@waeup.org>',
     1673             u'msg: Subject: Request for referee report from Sample University',
     1674             u'msg: ',
     1675            ], self.get_fake_smtp_output().split('\n')[:10]
     1676            )
     1677        self.assertTrue(
     1678            'Application submitted' in self.browser.contents)
     1679        logfile = os.path.join(
     1680            self.app['datacenter'].storage, 'logs', 'applicants.log')
     1681        logcontent = open(logfile).read()
     1682        self.assertTrue(
     1683            '%s - applicants.browser.ApplicantEditFormPage - %s - '
     1684            'email sent: otis@stones.de' %
     1685            (self.applicant.applicant_id, self.applicant.applicant_id)
     1686            in logcontent)
     1687        self.assertTrue(referee1.email_sent)
     1688        self.assertTrue(referee2.email_sent)
     1689        return
Note: See TracChangeset for help on using the changeset viewer.