コード例 #1
0
    def test_activate_invalid(self):
        from pyramid_signup.views import RegisterController
        from pyramid_signup.models import User
        from pyramid_signup.models import Activation
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_signup.managers import UserManager
        self.config.include('pyramid_signup')
        self.config.add_route('index', '/')

        self.config.registry.registerUtility(DummyMailer(), IMailer)

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

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

        request = testing.DummyRequest()
        request.matchdict = Mock()
        get = Mock()
        get.return_value = 'invalid'
        request.matchdict.get = get

        controller = RegisterController(request)
        response = controller.activate()
        mgr = UserManager(request)
        user = mgr.get_by_username('sontek')

        assert not user.activated
        assert response.status_int == 404
コード例 #2
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    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.register()

        assert response.status_int == 302

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

        assert user != None
コード例 #3
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    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.register()

        flash.assert_called_with('I broke!', 'error')
コード例 #4
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')
コード例 #5
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    def test_activate_invalid(self):
        from pyramid_signup.views import RegisterController
        from pyramid_signup.models import User
        from pyramid_signup.models import Activation
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_signup.managers import UserManager
        self.config.include('pyramid_signup')
        self.config.add_route('index', '/')

        self.config.registry.registerUtility(DummyMailer(), IMailer)

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

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

        request = testing.DummyRequest()
        request.matchdict = Mock()
        get = Mock()
        get.return_value = 'invalid'
        request.matchdict.get = get

        controller = RegisterController(request)
        response = controller.activate()
        mgr = UserManager(request)
        user = mgr.get_by_username('sontek')

        assert not user.activated
        assert response.status_int == 404
コード例 #6
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')
コード例 #7
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
コード例 #8
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    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.register()

        flash.assert_called_with(u'That username is already used.', 'error')
コード例 #9
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    def test_register_redirects_if_logged_in(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 = testing.DummyRequest()
        request.user = Mock()
        controller = RegisterController(request)
        response = controller.register()

        assert response.status_int == 302
コード例 #10
0
    def test_register_controller_extensions_without_mail(self):
        from pyramid_signup.views import RegisterController
        from pyramid_signup.interfaces import ISURegisterSchema
        from pyramid_signup.interfaces import ISURegisterForm

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

        request = testing.DummyRequest()

        getUtility = Mock()
        getUtility.return_value = True

        schema = Mock()
        form = Mock()

        self.config.registry.settings['su.require_activation'] = False
        self.config.registry.registerUtility(schema, ISURegisterSchema)
        self.config.registry.registerUtility(form, ISURegisterForm)

        with patch('pyramid_signup.views.get_mailer') as get_mailer:
            RegisterController(request)
            assert not get_mailer.called

        schema.assert_called_once_with()
        assert form.called
コード例 #11
0
    def test_register_redirects_if_logged_in(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 = testing.DummyRequest()
        request.user = Mock()
        controller = RegisterController(request)
        response = controller.get()

        assert response.status_int == 302
コード例 #12
0
    def test_register_loads_not_logged_in(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 = testing.DummyRequest()
        request.user = None
        controller = RegisterController(request)
        response = controller.get()

        assert response.get('form', None)
コード例 #13
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    def test_register_loads_not_logged_in(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 = testing.DummyRequest()
        request.user = None
        controller = RegisterController(request)
        response = controller.register()

        assert response.get('form', None)
コード例 #14
0
    def test_register_controller_extensions_with_mail(self):
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from pyramid_signup.views import RegisterController
        from pyramid_signup.interfaces import ISURegisterSchema
        from pyramid_signup.interfaces import ISURegisterForm

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

        request = testing.DummyRequest()

        getUtility = Mock()
        getUtility.return_value = True

        schema = Mock()
        form = Mock()

        self.config.registry.registerUtility(schema, ISURegisterSchema)
        self.config.registry.registerUtility(form, ISURegisterForm)
        self.config.registry.registerUtility(DummyMailer(), IMailer)

        with patch('pyramid_signup.views.get_mailer') as get_mailer:
            RegisterController(request)
            assert get_mailer.called

        assert schema.called
        assert form.called
コード例 #15
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    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')

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

        request.user = Mock()

        controller = RegisterController(request)
        response = controller.register()

        assert response.status_int == 302

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

        assert user.activated == True
        flash.assert_called_with('You have been registered, you may login now!', 'success')
コード例 #16
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']
コード例 #17
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    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.register()

        assert len(response['errors']) == 3
        assert 'There was a problem with your submission' in response['form']
コード例 #18
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    def test_activate_invalid_user(self):
        from pyramid_signup.views import RegisterController
        from pyramid_signup.models import User
        from pyramid_signup.models import Activation
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_signup.managers import UserManager
        self.config.include('pyramid_signup')
        self.config.add_route('index', '/')

        self.config.registry.registerUtility(DummyMailer(), IMailer)

        bad_act = Activation()

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

        user2 = User(username='******', password='******')
        user2.activation = bad_act

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

        request = testing.DummyRequest()
        request.matchdict = Mock()

        def get(val, ret):
            if val == 'code':
                return bad_act.code
            elif val == 'user_pk':
                return user.pk

        request.matchdict.get = get

        controller = RegisterController(request)
        response = controller.activate()
        mgr = UserManager(request)
        new_user1 = mgr.get_by_username('sontek')
        new_user2 = mgr.get_by_username('jessie')

        assert not new_user1.activated
        assert not new_user2.activated
        assert response.status_int == 404
コード例 #19
0
ファイル: test_views.py プロジェクト: whitmo/pyramid_signup
    def test_activate_multiple_users(self):
        from pyramid_signup.views import RegisterController
        from pyramid_signup.models import User
        from pyramid_signup.models import Activation
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_signup.managers import UserManager
        from pyramid_signup.managers import ActivationManager
        self.config.include('pyramid_signup')
        self.config.add_route('index', '/')

        self.config.registry.registerUtility(DummyMailer(), IMailer)

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

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

        request = testing.DummyRequest()
        request.matchdict = Mock()

        def get(key, default):
            if key == 'code':
                return user1.activation.code
            else:
                return user1.pk

        request.matchdict.get = get

        controller = RegisterController(request)
        response = controller.activate()
        mgr = UserManager(request)
        user = mgr.get_by_username('sontek1')

        act_mgr = ActivationManager(request)
        activations = act_mgr.get_all()

        assert len(activations) == 1
        assert user.activated
        assert response.status_int == 302
コード例 #20
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