Ejemplo n.º 1
0
    def test_send_only_plain(self):
        test_service = TestEmailService()
        self.mox.StubOutWithMock(email_service, 'get_service_client')
        email_service.get_service_client(
            tiny_classified.get_config()['EMAIL_USERNAME'],
            tiny_classified.get_config()['EMAIL_PASSWORD'],
            tiny_classified.get_config()['EMAIL_USE_SECURE'],
        ).AndReturn(test_service)
        self.mox.ReplayAll()

        email_service.send(
            ['*****@*****.**'],
            'subject',
            '**plain_body**'
        )

        message = test_service.web.message
        mesg_dict = message.__dict__
        self.assertEqual(
            mesg_dict['from_email'],
            tiny_classified.get_config()['EMAIL_FROM_ADDR']
        )
        self.assertEqual(mesg_dict['to'], ['*****@*****.**'])
        self.assertEqual(mesg_dict['subject'], 'subject')
        self.assertEqual(mesg_dict['text'], '**plain_body**')
        self.assertEqual(mesg_dict['html'], '<p><strong>plain_body</strong></p>')
Ejemplo n.º 2
0
def update_password(user, password, send_email=True,
    include_password_in_email=True):
    """Update a user's password and optionally send an email with password.

    @param user: The user hash.
    @type email_or_user: dict
    @param password: User's new plain text password
    @type password: str
    @param include_password_in_email: Flag indicating if the new password should
        be sent with the email notification about the password change.
    @type include_password_in_email: bool
    """
    pass_hash = werkzeug.generate_password_hash(password, method='sha512')
    user['password_hash'] = pass_hash
    update(user['email'], user)

    if include_password_in_email:
        plaintext_message = NEW_PASSWORD_EMAIL_WITH_PASS % password
    else:
        plaintext_message = NEW_PASSWORD_EMAIL_WITHOUT_PASS

    if send_email:
        email_service.send(
            [user['email']],
            PASSWORD_EMAIL_SUBJECT,
            plaintext_message
        )
Ejemplo n.º 3
0
    def test_update_password_send_email(self):
        test_user = copy.deepcopy(TEST_USER)
        new_pass = '******'

        self.mox.StubOutWithMock(user_service, 'update')
        user_service.update(test_user['email'], mox.IsA(dict))

        self.mox.StubOutWithMock(email_service, 'send')
        email_service.send(
            [test_user['email']],
            user_service.PASSWORD_EMAIL_SUBJECT,
            mox.IsA(basestring)
        )

        self.mox.ReplayAll()

        user_service.update_password(test_user, new_pass, True, False);