Example #1
0
    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)
Example #2
0
 def setUp(self):
     super(StaffModelTests, self).setUp()
     with transaction.manager:
         staff1 = Staff(  # german
             login=u'SomeFoonäme',
             email=u'*****@*****.**',
             password=u"12345",
         )
         DBSession.add(staff1)
         DBSession.flush()
Example #3
0
 def _insert_abos(self):
     with transaction.manager:
         abo1 = Abo(  # english
             name=u'SomeAliasnäme',
             email=u'*****@*****.**',
             amount=u'23',
         )
         abo1.locale = u'en'
         abo2 = Abo(  # german
             name=u'AAASomeFirstnäme',
             email=u'*****@*****.**',
             amount=u'42',
         )
         abo2.locale = u'de'
         DBSession.add(abo1)
         DBSession.add(abo2)
         DBSession.flush()
Example #4
0
 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
Example #5
0
 def setUp(self):
     super(ZaboModelTests, self).setUp()
     with transaction.manager:
         abo1 = Abo(  # englisch
             name=u'SomeFirstnäme',
             email=u'*****@*****.**',
             amount=u"12345",
         )
         abo1.locale = u'en'
         abo1.refcode = u'ABCXXSustainC3S'
         DBSession.add(abo1)
         abo2 = Abo(  # german
             name=u'SomeOthernäme',
             email=u'*****@*****.**',
             amount=u"12345",
         )
         abo2.locale = u'de'
         DBSession.add(abo2)
         DBSession.flush()
Example #6
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)
Example #7
0
    def setUp(self):
        self.config = testing.setUp()
        self.config.include('pyramid_mailer.testing')
        try:
            DBSession.close()
            DBSession.remove()
            #print "closed and removed DBSession"
        except:
            pass
            #print "no session to close"
        my_settings = {
            'sqlalchemy.url': 'sqlite:///:memory:',
            'available_languages': 'da de en es fr',
            'zabo.dashboard_number': '32',
            'foo': 'bar',
            'mailrecipient': '*****@*****.**',
            'mail.debug': True,
            'mail_from': '*****@*****.**',
            'pyramid.includes': 'pyramid_mailer.testing',
            'the_url': 'http://example.com',
            'financial_blog_url_de': 'https://www.c3s.cc/ueber-c3s/finanzierung/',
            'financial_blog_url_en': 'https://www.c3s.cc/en/about-us//financing/',
            'base_path': '.'
        }
        engine = engine_from_config(my_settings)
        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)

        self._insert_abos()

        with transaction.manager:
            # a group for accountants/staff
            accountants_group = Group(name=u"staff")
            try:
                DBSession.add(accountants_group)
                DBSession.flush()
                #print("adding group staff")
            except:
                print("could not add group staff.")
                # pass
            # staff personnel
            staffer1 = Staff(
                login=u"rut",
                password=u"berries",
                email=u"*****@*****.**",
            )
            staffer1.groups = [accountants_group]
            try:
                DBSession.add(accountants_group)
                DBSession.add(staffer1)
                DBSession.flush()
            except:
                print("could not add staffer1")
                # pass

        from zabo import main
        import pyramid
        registry = pyramid.registry.Registry()
        app = main({}, registry=registry, **my_settings)
        from webtest import TestApp
        self.testapp = TestApp(app)