示例#1
0
    def test_inactive_login_fails(self):
        """ Make sure we can't login with an inactive user """
        from pyramid_signup.models import User
        user = User(username='******', password='******')

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

        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
            'submit': True,
            'Username': '******',
            'Password': '******',
        },
                                        request_method='POST')

        flash = Mock()

        request.session.flash = flash

        view = AuthController(request)
        view.login()

        flash.assert_called_with(
            u'Your account is not active, please check your e-mail.', 'error')
示例#2
0
    def test_login_succeeds(self):
        """ Make sure we can login """
        from pyramid_signup.models import User
        admin = User(username='******', password='******')
        admin.activated = True

        self.session.add(admin)
        self.session.flush()

        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')

        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
            'submit': True,
            'Username': '******',
            'Password': '******',
        },
                                        request_method='POST')

        view = AuthController(request)
        response = view.login()

        assert response.status_int == 302
示例#3
0
    def test_inactive_login_fails(self):
        """ Make sure we can't login with an inactive user """
        from pyramid_signup.models import User
        user = User(username='******', password='******')

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

        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
                'submit': True,
                'Username': '******',
                'Password': '******',
            }, request_method='POST')

        flash = Mock()

        request.session.flash = flash

        view = AuthController(request)
        view.login()

        flash.assert_called_with(u'Your account is not active, please check your e-mail.',
            'error')
示例#4
0
    def test_login_loads(self):
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = testing.DummyRequest()
        request.user = None
        view = AuthController(request)
        response = view.login()

        assert response.get('form', None)
示例#5
0
    def test_login_redirects_if_logged_in(self):
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = testing.DummyRequest()
        request.user = Mock()
        view = AuthController(request)

        response = view.login()
        assert response.status_int == 302
示例#6
0
    def test_login_redirects_if_logged_in(self):
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = testing.DummyRequest()
        request.user = Mock()
        view = AuthController(request)

        response = view.login()
        assert response.status_int == 302
示例#7
0
    def test_login_loads(self):
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = testing.DummyRequest()
        request.user = None
        view = AuthController(request)
        response = view.login()

        assert response.get('form', None)
示例#8
0
    def test_login_fails_bad_credentials(self):
        """ Make sure we can't login with bad credentials"""
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
                'submit': True,
                'Username': '******',
                'Password': '******',
            }, request_method='POST')

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

        view = AuthController(request)
        view.login()

        flash.assert_called_with(u'Invalid username or password.', 'error')
示例#9
0
    def test_login_fails_empty(self):
        """ Make sure we can't login with empty credentials"""
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = testing.DummyRequest(post={
            'submit': True,
        }, request_method='POST')

        view = AuthController(request)
        response = view.login()
        errors = response['errors']

        assert errors[0].node.name == u'csrf_token'
        assert errors[0].msg == u'Required'
        assert errors[1].node.name == u'Username'
        assert errors[1].msg == u'Required'
        assert errors[2].node.name == u'Password'
        assert errors[2].msg == u'Required'
示例#10
0
    def test_login_fails_bad_credentials(self):
        """ Make sure we can't login with bad credentials"""
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
            'submit': True,
            'Username': '******',
            'Password': '******',
        },
                                        request_method='POST')

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

        view = AuthController(request)
        view.login()

        flash.assert_called_with(u'Invalid username or password.', 'error')
示例#11
0
    def test_login_fails_empty(self):
        """ Make sure we can't login with empty credentials"""
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = testing.DummyRequest(post={
            'submit': True,
        },
                                       request_method='POST')

        view = AuthController(request)
        response = view.login()
        errors = response['errors']

        assert errors[0].node.name == u'csrf_token'
        assert errors[0].msg == u'Required'
        assert errors[1].node.name == u'Username'
        assert errors[1].msg == u'Required'
        assert errors[2].node.name == u'Password'
        assert errors[2].msg == u'Required'
示例#12
0
    def test_csrf_invalid_fails(self):
        """ Make sure we can't login with a bad csrf """
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
                    'submit': True,
                    'login': '******',
                    'password': '******',
                    'csrf_token': 'abc2'
                }, request_method='POST')

        view = AuthController(request)

        response = view.login()

        errors = response['errors']

        assert errors[0].node.name == u'csrf_token'
        assert errors[0].msg == u'Invalid cross-site scripting token'
示例#13
0
    def test_csrf_invalid_fails(self):
        """ Make sure we can't login with a bad csrf """
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
            'submit': True,
            'login': '******',
            'password': '******',
            'csrf_token': 'abc2'
        },
                                        request_method='POST')

        view = AuthController(request)

        response = view.login()

        errors = response['errors']

        assert errors[0].node.name == u'csrf_token'
        assert errors[0].msg == u'Invalid cross-site scripting token'
示例#14
0
    def test_logout(self):
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')
        request = testing.DummyRequest()

        flash = Mock()
        invalidate = Mock()

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

        view = AuthController(request)
        with patch('pyramid_signup.views.forget') as forget:
            with patch('pyramid_signup.views.HTTPFound') as HTTPFound:
                view.logout()
                flash.assert_called_with(u'Logged out successfully.', 'success')
                forget.assert_called_with(request)
                assert invalidate.called
                assert HTTPFound.called
示例#15
0
    def test_logout(self):
        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('pyramid_signup')
        request = testing.DummyRequest()

        flash = Mock()
        invalidate = Mock()

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

        view = AuthController(request)
        with patch('pyramid_signup.views.forget') as forget:
            with patch('pyramid_signup.views.HTTPFound') as HTTPFound:
                view.logout()
                flash.assert_called_with(u'Logged out successfully.',
                                         'success')
                forget.assert_called_with(request)
                assert invalidate.called
                assert HTTPFound.called
示例#16
0
    def test_login_succeeds(self):
        """ Make sure we can login """
        from pyramid_signup.models import User
        admin = User(username='******', password='******')
        admin.activated = True

        self.session.add(admin)
        self.session.flush()

        from pyramid_signup.views import AuthController
        self.config.add_route('index', '/')

        self.config.include('pyramid_signup')

        request = self.get_csrf_request(post={
                'submit': True,
                'Username': '******',
                'Password': '******',
            }, request_method='POST')

        view = AuthController(request)
        response = view.login()

        assert response.status_int == 302
示例#17
0
    def test_auth_controller_extensions(self):
        from pyramid_signup.views import AuthController
        from pyramid_signup.interfaces import ISULoginSchema
        from pyramid_signup.interfaces import ISULoginForm

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

        request = testing.DummyRequest()

        getUtility = Mock()
        getUtility.return_value = True

        schema = Mock()
        form = Mock()

        self.config.registry.registerUtility(schema, ISULoginSchema)
        self.config.registry.registerUtility(form, ISULoginForm)

        AuthController(request)

        assert schema.called
        assert form.called