Ignore:
Timestamp:
10 Sep 2020, 07:22:19 (4 years ago)
Author:
Henrik Bettermann
Message:

Implement ContactApplicantFormPage.

File:
1 edited

Legend:

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

    r16215 r16231  
    3737from zope.security.interfaces import Unauthorized
    3838from zope.testbrowser.testing import Browser
     39from zope.interface import implementedBy
     40from zope.schema.fieldproperty import FieldProperty
    3941from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    4042from waeup.kofa.browser.tests.test_pdf import samples_dir
     
    583585    layer = FunctionalLayer
    584586
     587    def setUp(self):
     588        super(ApplicantUITests, self).setUp()
     589        self.setup_logging()
     590        return
     591
     592    def tearDown(self):
     593        super(ApplicantUITests, self).tearDown()
     594        self.teardown_logging()
     595        return
     596
     597    def setup_logging(self):
     598        # setup a log-handler that catches all fake mailer output
     599        self.stream = StringIO()
     600        handler = logging.StreamHandler(self.stream)
     601        logger = logging.getLogger('test.smtp')
     602        logger.addHandler(handler)
     603        logger.setLevel(logging.INFO)
     604        return
     605
     606    def get_fake_smtp_output(self):
     607        # get output generated by fake mailer
     608        self.stream.flush()
     609        self.stream.seek(0)
     610        return self.stream.read()
     611
     612    def teardown_logging(self):
     613        # remove the log handler for fake mailer output
     614        logger = logging.getLogger('test.smtp')
     615        handlers = [x for x in logger.handlers]
     616        for handler in handlers:
     617            logger.removeHandler(handler)
     618        return
     619
    585620    def test_manage_and_view_applicant(self):
    586621        # Managers can manage applicants
     
    623658        # If applicant is in correct state the pdf slip can be opened.
    624659        IWorkflowState(self.applicant).setState('submitted')
    625         self.browser.open(self.manage_path)
     660        self.browser.open(self.view_path)
    626661        self.browser.getLink("Download application slip").click()
    627662        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     
    924959        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
    925960        self.browser.getControl("Save").click() # submit form
    926         self.browser.open(self.manage_path)
     961        self.browser.open(self.view_path)
    927962        self.browser.getLink("Download application slip").click()
    928963        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     
    13311366        return
    13321367
     1368    def test_manage_contact_applicant(self):
     1369        # Managers can contact student
     1370        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1371        # Remove required FieldProperty attribute first ...
     1372        delattr(Applicant, 'email')
     1373        # ... and replace by None
     1374        self.applicant.email = None
     1375        # Now we have to add  the FieldProperty attribute again. Otherwise
     1376        # many other tests below will fail.
     1377        iface = list(implementedBy(Applicant))[0]
     1378        field_property = FieldProperty(iface['email'])
     1379        setattr(Applicant, 'email', field_property)
     1380        self.browser.open(self.view_path)
     1381        self.browser.getLink("Send email").click()
     1382        self.browser.getControl(
     1383            name="form.subject").value = 'Important subject'
     1384        self.browser.getControl(name="form.body").value = 'Hello!'
     1385        self.browser.getControl("Send message now").click()
     1386        self.assertTrue(
     1387            'An smtp server error occurred' in self.browser.contents)
     1388        self.applicant.email = 'xx@yy.zz'
     1389        self.browser.getControl("Send message now").click()
     1390        self.assertTrue('Your message has been sent' in self.browser.contents)
     1391        self.assertMatches(
     1392            'Sending email from no-reply@waeup.org to xx@yy.zz:'
     1393            '\nMessage:'
     1394            '\nmsg: MIME-Version: 1.0'
     1395            '\nmsg: Content-Type: text/plain; charset="us-ascii"'
     1396            '\nmsg: Content-Transfer-Encoding: 7bit'
     1397            '\nmsg: From: Manager <no-reply@waeup.org>'
     1398            '\nmsg: To: Joan None <xx@yy.zz>'
     1399            '\nmsg: Reply-To: Manager <contact@waeup.org>'
     1400            '\nmsg: Subject: Important subject'
     1401            '\nmsg:'
     1402            '\nmsg: Hello!'
     1403            '\nmsg:'
     1404            '\nmsg: ---'
     1405            '\nmsg: Manager (id: zope.mgr)'
     1406            '\nmsg: Sample University'
     1407            '\nmsg:',
     1408            self.get_fake_smtp_output()
     1409            )
     1410        return
     1411
    13331412
    13341413class ApplicantRegisterTests(ApplicantsFullSetup):
     
    19562035        # Managers can remind referees
    19572036        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    1958         self.browser.open(self.manage_path)
     2037        self.browser.open(self.view_path)
    19592038        self.browser.getLink("Remind referees").click()
    19602039        self.assertTrue('2 referee(s) have been reminded by email.'
     
    20352114        report.email = 'linda@forest.de'
    20362115        self.applicant[report.r_id] = report
    2037         self.browser.open(self.manage_path)
     2116        self.browser.open(self.view_path)
    20382117        self.browser.getLink("Remind referees").click()
    20392118        self.assertTrue('1 referee(s) have been reminded by email.'
Note: See TracChangeset for help on using the changeset viewer.