Ignore:
Timestamp:
3 Feb 2015, 16:54:56 (10 years ago)
Author:
Henrik Bettermann
Message:

Notify customer by email after customer and contract transitions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12540 r12553  
    2121import shutil
    2222import tempfile
     23import logging
    2324import pytz
    2425import base64
     
    301302    # Tests for Customer class views and pages
    302303
     304
     305    def setup_logging(self):
     306        # setup a log-handler that catches all fake mailer output
     307        self.stream = StringIO()
     308        handler = logging.StreamHandler(self.stream)
     309        logger = logging.getLogger('test.smtp')
     310        logger.addHandler(handler)
     311        logger.setLevel(logging.INFO)
     312        return
     313
     314    def get_fake_smtp_output(self):
     315        # get output generated by fake mailer
     316        self.stream.flush()
     317        self.stream.seek(0)
     318        return self.stream.read()
     319
     320    def teardown_logging(self):
     321        # remove the log handler for fake mailer output
     322        logger = logging.getLogger('test.smtp')
     323        handlers = [x for x in logger.handlers]
     324        for handler in handlers:
     325            logger.removeHandler(handler)
     326        return
     327
    303328    def test_basic_auth(self):
    304329        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     
    386411
    387412
    388     def test_manage_workflow(self):
     413    def test_manage_workflow_send_transition_information(self):
    389414        # Managers can pass through the whole workflow
     415        config = grok.getSite()['configuration']
     416        config.email_notification = True
     417        self.setup_logging()
    390418        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    391419        customer = self.app['customers'][self.customer_id]
     
    399427        self.browser.getControl(name="transition").value = ['reject']
    400428        self.browser.getControl("Apply").click()
     429        # The customer is being notified by email after rejection
     430        expected = [
     431            u'Sending email from no-reply@waeup.org to aa@aa.ng:',
     432            u'Message:', u'msg: MIME-Version: 1.0',
     433            u'msg: Content-Type: text/plain; charset="us-ascii"',
     434            u'msg: Content-Transfer-Encoding: 7bit',
     435            u'msg: From: Administrator <no-reply@waeup.org>',
     436            u'msg: To: Anna Tester <aa@aa.ng>',
     437            u'msg: Reply-To: Administrator <contact@waeup.org>',
     438            u'msg: Subject: Ikoba status change information',
     439            u'msg: ',
     440            u'msg: Dear Anna Tester,',
     441            u'msg: ',
     442            u'msg: The status of the following object has been changed:',
     443            u'msg: ', u'msg: Object Id: K1000000',
     444            u'msg: Title: Anna Tester',
     445            u'msg: Transition: customer registration rejected',
     446            u'msg: New state: started',
     447            u'msg: ',
     448            u'msg: Regards,',
     449            u'msg: ',
     450            u'msg: Manager',
     451            u'msg: ',
     452            u'msg: --',
     453            u'msg: Sample Company',
     454            u'msg: ',
     455            u'']
     456        self.assertEqual(expected, self.get_fake_smtp_output().split('\n'))
    401457        self.browser.open(self.trigtrans_path)
    402458        self.browser.getControl(name="transition").value = ['request']
     
    411467        self.browser.getControl(name="transition").value = ['reset1']
    412468        self.browser.getControl("Apply").click()
     469        self.teardown_logging()
    413470        return
    414471
Note: See TracChangeset for help on using the changeset viewer.