예제 #1
0
파일: tests.py 프로젝트: AnneGilles/zabo
    def test_mail_utils(self):
        from zabo.mail_utils import mailbody_transfer_received
        # first, create an abo in the DB and thus an id to match
        new_abo = Abo(
            name=u'foobar',
            email=u'*****@*****.**',
            amount=u'23'
        )
        new_abo.linkcode = u'ABCDEFGHIJKAbo'
        new_abo.locale = u'de'
        DBSession.add(new_abo)
        DBSession.flush()
        assert(new_abo.id == 2)
        old_abo = Abo.get_by_id(1)
        old_abo.locale = u'en'
        _url = 'http://foobar.com'
        # englisch
        result1 = mailbody_transfer_received(old_abo, _url)
        #print result1
        self.assertTrue('Hello' in result1)

        # german
        result2 = mailbody_transfer_received(new_abo, _url)
        #print result2
        self.assertTrue('Hallo' in result2)
예제 #2
0
파일: tests.py 프로젝트: AnneGilles/zabo
 def test_send_mail_view(self):
     '''
     tests for the send_email_view view in backend_views.py
     i.e. to send out transfer information emails
     '''
     from zabo.backend_views import send_mail_view
     self.config.add_route('dash', '/dash')
     '''
     if the requested id does not exist, redirect to the dashboard
     '''
     request = testing.DummyRequest()
     request.registry.settings['the_url'] = 'http://foobar.com'
     request.registry.settings['mail_from'] = '*****@*****.**'
     request.matchdict['abo_id'] = u'1foo'  # does not exist
     result = send_mail_view(request)
     #print result.location
     self.assertTrue('dash' in result.location)  # redirected
     '''
     if the id does exist, send email
     '''
     # first, create an abo in the DB and thus an id to match
     new_abo = Abo(
         name=u'foobar',
         email=u'*****@*****.**',
         amount=u'23'
     )
     new_abo.linkcode = u'ABCDEFGHIJKAbo'
     DBSession.add(new_abo)
     DBSession.flush()
     assert(new_abo.id == 2)
     request = testing.DummyRequest()
     #print type(new_abo.linkcode)
     request.matchdict['abo_id'] = new_abo.id  # does exist
     from pyramid_mailer import get_mailer
     mailer = get_mailer(request)
     result = send_mail_view(request)
     self.assertEqual(len(mailer.outbox), 1)
     self.assertEqual(
         mailer.outbox[0].subject,
         u"You sustain C3S: Deine Links!")
     #print dir(mailer.outbox[0])
     self.assertTrue(new_abo.linkcode in mailer.outbox[0].body)
     #print result.location
     self.assertTrue('dash' in result.location)  # redirected
예제 #3
0
    def test_html_and_png(self):
        """
        load the page and image for use by the sponsor
        """
        # make
        from zabo.models import Abo
        new_abo = Abo(
            name=u'oleander',
            email=u'*****@*****.**',
            amount=u'23',
        )
        new_abo.locale = u'de'
        # set the linkcode to sth, which is usually done via button in backend
        new_abo.linkcode = u'YES_THIS_ONE'
        DBSession.add(new_abo)
        DBSession.flush()

        '''
        image
        '''
        image = self.testapp.get(
            '/verify/{}.png'.format(new_abo.linkcode), status=200)
        #print len(image.body)
        self.failUnless(85000 < len(image.body) < 90000)  # check size of image
        '''
        html page
        '''
        html = self.testapp.get(
            '/verify/{}.html'.format(new_abo.linkcode), status=200)
        #print html.body
        # link to image must be in html
        self.failUnless(
            '/verify/{}.png'.format(new_abo.linkcode) in html.body)
        self.failUnless('<small>Thanks,</small>' in html.body)
        #self.failUnless('<small>Contribution by</small>' in html.body)
        self.failUnless(new_abo.name in html.body)