Beispiel #1
0
    def test_registration_craps_out(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.interfaces import IMailer

        def send(message):
            raise Exception("I broke!")

        mailer = Mock()
        mailer.send = send

        self.config.include('pyramid_signup')
        self.config.registry.registerUtility(mailer, IMailer)

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

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

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

        request.user = Mock()
        controller = RegisterController(request)
        controller.post()

        flash.assert_called_with('I broke!', 'error')
Beispiel #2
0
    def test_register_existing_user(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from pyramid_signup.models import User

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

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

        admin = User(username='******', password='******')
        self.session.add(admin)
        self.session.flush()

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

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

        controller = RegisterController(request)
        controller.post()

        flash.assert_called_with(u'That username is already used.', 'error')
    def test_registration_craps_out(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.interfaces import IMailer

        def send(message):
            raise Exception("I broke!")

        mailer = Mock()
        mailer.send = send

        self.config.include('pyramid_signup')
        self.config.registry.registerUtility(mailer, IMailer)

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

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

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

        request.user = Mock()
        controller = RegisterController(request)
        controller.post()

        flash.assert_called_with('I broke!', 'error')
    def test_register_existing_user(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from pyramid_signup.models import User

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

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

        admin = User(username='******', password='******')
        self.session.add(admin)
        self.session.flush()

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

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

        controller = RegisterController(request)
        controller.post()

        flash.assert_called_with(u'That username is already used.', 'error')
Beispiel #5
0
    def test_register_creates_user(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from pyramid_signup.managers import UserManager

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

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

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

        request.user = Mock()
        controller = RegisterController(request)
        response = controller.post()

        assert response.status_int == 302

        mgr = UserManager(request)
        user = mgr.get_by_username('admin')

        assert user != None
    def test_register_creates_user(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from pyramid_signup.managers import UserManager

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

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

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

        request.user = Mock()
        controller = RegisterController(request)
        response = controller.post()

        assert response.status_int == 302

        mgr = UserManager(request)
        user = mgr.get_by_username('admin')

        assert user != None
Beispiel #7
0
    def test_register_validation(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer

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

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

        request = self.get_csrf_request(request_method='POST')

        request.user = Mock()
        controller = RegisterController(request)
        response = controller.post()

        assert len(response['errors']) == 3
        assert 'There was a problem with your submission' in response['form']
    def test_register_validation(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer

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

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

        request = self.get_csrf_request(request_method='POST')

        request.user = Mock()
        controller = RegisterController(request)
        response = controller.post()

        assert len(response['errors']) == 3
        assert 'There was a problem with your submission' in response['form']
Beispiel #9
0
    def test_register_no_email_validation(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from pyramid_signup.managers import UserManager
        from pyramid_signup.interfaces import ISUSession
        from pyramid_signup.events import NewRegistrationEvent

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

        self.config.add_route('index', '/')
        self.config.registry.settings['su.require_activation'] = False

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

        self.config.add_subscriber(handle_registration, NewRegistrationEvent)

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

        request.user = Mock()
        controller = RegisterController(request)
        response = controller.post()

        assert response.status_int == 302

        mgr = UserManager(request)
        user = mgr.get_by_username('admin')

        assert user.activated == True
Beispiel #10
0
    def test_register_no_email_validation(self):
        from pyramid_signup.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from pyramid_signup.managers import UserManager
        from pyramid_signup.interfaces import ISUSession
        from pyramid_signup.events import NewRegistrationEvent

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

        self.config.add_route('index', '/')
        self.config.registry.settings['su.require_activation'] = False

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

        self.config.add_subscriber(handle_registration, NewRegistrationEvent)


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

        request.user = Mock()
        controller = RegisterController(request)
        response = controller.post()

        assert response.status_int == 302

        mgr = UserManager(request)
        user = mgr.get_by_username('admin')

        assert user.activated == True