Exemplo n.º 1
0
    def test_profile_update_password(self):
        from pyramid_signup.views import ProfileController
        from pyramid_signup.managers import UserManager
        from pyramid_signup.interfaces import ISUSession
        from pyramid_signup.events import ProfileUpdatedEvent
        from pyramid_signup.models import crypt

        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        from pyramid_signup.models import User

        user = User(username='******', password='******', email='*****@*****.**',
            activated=True)

        self.session.add(user)
        self.session.flush()

        def handle_profile_updated(event):
            request = event.request
            session = request.registry.getUtility(ISUSession)
            session.commit()

        self.config.add_subscriber(handle_profile_updated, ProfileUpdatedEvent)


        request = self.get_csrf_request(post={
            'First_Name': 'John',
            'Last_Name': 'Anderson',
            'Email': '*****@*****.**',
            'Password': {
                'value': 'test123',
                'confirm': 'test123',
            },
        }, request_method='POST')

        request.user = user

        request.matchdict = Mock()
        get = Mock()
        get.return_value = user.pk
        request.matchdict.get = get


        flash = Mock()
        request.session.flash = flash

        view = ProfileController(request)

        view.profile()
        mgr = UserManager(request)
        new_user = mgr.get_by_pk(user.pk)

        assert new_user.first_name == 'John'
        assert new_user.last_name == 'Anderson'
        assert new_user.email == '*****@*****.**'
        assert not crypt.check(user.password, 'temp' + user.salt)
Exemplo n.º 2
0
    def test_reset_password_valid_user(self):
        from pyramid_signup.views import ForgotPasswordController
        from pyramid_signup.interfaces import ISUSession
        from pyramid_signup.events import PasswordResetEvent
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_signup.models import User
        from pyramid_signup.models import Activation
        from pyramid_signup.models import crypt


        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')
        self.config.registry.registerUtility(DummyMailer(), IMailer)

        user = User(username='******', password='******', email='*****@*****.**')
        user.activation = Activation()

        self.session.add(user)
        self.session.flush()

        request = self.get_csrf_request(post={
            'Password': {
                'value': 'test123',
                'confirm': 'test123',
            },
        }, request_method='POST')

        request.matchdict = Mock()
        get = Mock()
        get.return_value = user.activation.code
        request.matchdict.get = get

        request.user = None

        flash = Mock()
        request.session.flash = flash

        def handle_password_reset(event):
            request = event.request
            session = request.registry.getUtility(ISUSession)
            session.commit()

        self.config.add_subscriber(handle_password_reset, PasswordResetEvent)

        view = ForgotPasswordController(request)
        response = view.reset_password()

        assert not crypt.check(user.password, 'temp' + user.salt)
        assert response.status_int == 302