示例#1
0
文件: users.py 项目: altai/altai-api
def _invite_user(user, data):
    inv = InvitesDAO.create(user.id, user.email)
    send_mail = data.get('send-invite-mail', True)
    if send_mail:
        send_invitation(user.email, inv.code,
                        data.get('link-template'),
                        greeting=getattr(user, 'fullname', ''))
    else:
        auth.assert_admin()
    return user_to_view(user, inv, send_code=not send_mail)
示例#2
0
文件: users.py 项目: altai/altai-api
def _invite_user(user, data):
    inv = InvitesDAO.create(user.id, user.email)
    send_mail = data.get('send-invite-mail', True)
    if send_mail:
        send_invitation(user.email,
                        inv.code,
                        data.get('link-template'),
                        greeting=getattr(user, 'fullname', ''))
    else:
        auth.assert_admin()
    return user_to_view(user, inv, send_code=not send_mail)
示例#3
0
    def test_send_invitation_ioerror(self):
        mail.mail.Mail(mail.current_app).send(mox.IsA(mail.mail.Message))\
                .AndRaise(IOError('HI'))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            try:
                mail.send_invitation('*****@*****.**', 'THE_CODE')
            except IOError, e:
                self.assertEquals('Failed to send e-mail', e.message)
            else:
示例#4
0
    def test_send_invitation_ioerror(self):
        mail.mail.Mail(mail.current_app).send(mox.IsA(mail.mail.Message))\
                .AndRaise(IOError('HI'))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            try:
                mail.send_invitation('*****@*****.**',
                                     'THE_CODE')
            except IOError, e:
                self.assertEquals('Failed to send e-mail', e.message)
            else:
示例#5
0
    def test_send_invitation_minimal(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertTrue(message.subject.startswith('Invitation'))
                self.assertTrue('Dear ' not in message.body)
                self.assertTrue('follow the link' not in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            mail.send_invitation('*****@*****.**', 'THE_CODE')
示例#6
0
    def test_send_invitation_minimal(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertTrue(message.subject.startswith('Invitation'))
                self.assertTrue('Dear ' not in message.body)
                self.assertTrue('follow the link' not in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            mail.send_invitation('*****@*****.**',
                                 'THE_CODE')
示例#7
0
    def test_send_invitation_works(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertTrue(message.subject.startswith('Invitation'))
                self.assertTrue('Dear User Userovich' in message.body)
                self.assertTrue(
                    'https://localhost/invites?code=THE_CODE' in message.body)
                self.assertTrue('TEST_INSTALLATION_NAME' in message.body)
                self.assertTrue(message.body.endswith('TEST_FOOTER'),
                                'Wrong footer: %r' % message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            mail.send_invitation('*****@*****.**', 'THE_CODE',
                                 'https://localhost/invites?code={{code}}',
                                 'User Userovich')
示例#8
0
    def test_send_invitation_works(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertTrue(message.subject.startswith('Invitation'))
                self.assertTrue('Dear User Userovich' in message.body)
                self.assertTrue('https://localhost/invites?code=THE_CODE'
                                in message.body)
                self.assertTrue('TEST_INSTALLATION_NAME' in message.body)
                self.assertTrue(message.body.endswith('TEST_FOOTER'),
                                'Wrong footer: %r' % message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())

        self.mox.ReplayAll()
        with self.app.test_request_context():
            g.config = self.config
            mail.send_invitation('*****@*****.**',
                                 'THE_CODE',
                                 'https://localhost/invites?code={{code}}',
                                 'User Userovich')