Esempio n. 1
0
    def test_send_certificate_email_english(self):
        """
        test the send_certificate_email view (english)
        """
        if DEBUG:
            print('test_send_certificate_email_english')
        from c3smembership.membership_certificate import send_certificate_email
        self.config.add_route('join', '/')
        self.config.add_route('dashboard', '/')
        self.config.add_route('certificate_pdf', '/')
        self.config.add_route('membership_listing_backend', '/')
        from pyramid_mailer import get_mailer
        request = testing.DummyRequest()
        request.matchdict = {
            'id': '2',
            'name': 'foobar',
            'token': 'hotzenplotz'  # WRONG/INVALID token
        }
        request.cookies['on_page'] = 1
        request.cookies['order'] = 'asc'
        request.cookies['orderby'] = 'id'

        mailer = get_mailer(request)
        result = send_certificate_email(request)
        # print result
        self.assertTrue(result.status_code == 404)  # not found
        self.assertEqual(len(mailer.outbox), 0)

        request.matchdict = {
            'id': '2',
            'name': 'foobar',
            'token': 'hotzenplotz123'
        }
        member2 = C3sMember.get_by_id(2)
        member2.membership_accepted = True

        # the request needs stuff to be in the cookie (for redirects)
        request.cookies['m_on_page'] = 23
        request.cookies['m_order'] = 'asc'
        request.cookies['m_orderby'] = 'id'
        request.referrer = 'dashboard'

        result = send_certificate_email(request)
        # print result
        self.assertTrue(result.status_code == 302)  # redirect

        self.assertEqual(len(mailer.outbox), 1)
        self.assertEqual(
            mailer.outbox[0].subject,
            u"C3S membership certificate"
        )
        # print mailer.outbox[0].body
        self.assertTrue(
            u"Hello AAASomeFirstnäme XXXSomeLastnäme,"
            in mailer.outbox[0].body)
        self.assertTrue(
            u"your personal membership certificate" in mailer.outbox[0].body)
Esempio n. 2
0
    def test_send_certificate_email_german(self):
        """
        test the send_certificate_email view (german)
        """
        if DEBUG:
            print('test_send_certificate_email_german')
        from c3smembership.membership_certificate import send_certificate_email
        self.config.add_route('join', '/')
        self.config.add_route('dashboard', '/')
        self.config.add_route('certificate_pdf', '/')
        self.config.add_route('membership_listing_backend', '/')
        from pyramid_mailer import get_mailer
        request = testing.DummyRequest()
        request.matchdict = {
            'id': '1',
            'name': 'foobar',
            'token': 'hotzenplotz'  # WRONG/INVALID token
        }
        request.cookies['on_page'] = 1
        request.cookies['order'] = 'asc'
        request.cookies['orderby'] = 'id'

        mailer = get_mailer(request)
        result = send_certificate_email(request)
        # print result
        self.assertTrue(result.status_code == 404)  # not found
        self.assertEqual(len(mailer.outbox), 0)

        request.matchdict = {
            'id': '1',
            'name': 'foobar',
            'token': 'hotzenplotz123'
        }
        request.referrer = 'dashboard'

        member1 = C3sMember.get_by_id(1)

        member1.membership_accepted = False
        self.assertEqual(result.status_code, 404)

        member1.membership_accepted = True
        member1.membership_loss_date = date.today() - timedelta(days=1)
        result = send_certificate_email(request)
        self.assertEqual(result.status_code, 404)

        member1.membership_accepted = True
        member1.membership_loss_date = None
        result = send_certificate_email(request)
        self.assertEqual(result.status_code, 302)

        self.assertEqual(len(mailer.outbox), 1)
        self.assertEqual(
            mailer.outbox[0].subject,
            u"C3S-Mitgliedsbescheinigung"
        )
        # print mailer.outbox[0].body
        self.assertTrue(
            u"Hallo SomeFirstnäme SomeLastnäme," in mailer.outbox[0].body)
        self.assertTrue(
            u"Deine persönliche Mitgliederbescheinig" in mailer.outbox[0].body)

        member1.membership_accepted = True
        member1.membership_loss_date = date.today() + timedelta(days=1)
        result = send_certificate_email(request)
        self.assertEqual(result.status_code, 302)

        self.assertEqual(len(mailer.outbox), 2)