Exemple #1
0
 def test_loginas_view_submit_unknown_user(self):
     from pyramid_bimt.models import User
     from pyramid_bimt.views.auth import LoginAs
     context = User.by_email('*****@*****.**')
     request = testing.DummyRequest(
         layout_manager=mock.Mock(),
         session=mock.Mock(),
     )
     form_values = {'email': '*****@*****.**'}
     request.user = context
     view = LoginAs(request)
     self.assertIsNone(view.login_as_success(form_values))
     request.session.flash.assert_called_once_with(
         u'User with that email does not exist.', 'error')
Exemple #2
0
 def test_loginas_view_submit_success(self):
     from pyramid_bimt.models import User
     from pyramid_bimt.views.auth import LoginAs
     context = User.by_email('*****@*****.**')
     request = testing.DummyRequest(
         layout_manager=mock.Mock(),
         session=mock.Mock(),
     )
     form_values = {'email': '*****@*****.**'}
     request.user = context
     view = LoginAs(request)
     resp = view.login_as_success(form_values)
     self.assertEqual(resp.location, 'http://example.com')
     request.session.flash.assert_called_once_with(
         u'You have successfully logged in as user "*****@*****.**".')
Exemple #3
0
 def test_loginas_view_submit_user_as_staff_member(self):
     from pyramid_bimt.models import User
     from pyramid_bimt.views.auth import LoginAs
     context = User.by_email('*****@*****.**')
     self.config.testing_securitypolicy(userid='*****@*****.**',
                                        permissive=False)
     request = testing.DummyRequest(
         layout_manager=mock.Mock(),
         session=mock.Mock(),
     )
     form_values = {'email': '*****@*****.**'}
     request.user = context
     view = LoginAs(request)
     self.assertIsNone(view.login_as_success(form_values))
     request.session.flash.assert_called_once_with(
         u'You do not have permission to login as staff user.', 'error')
Exemple #4
0
 def test_loginas_view(self):
     from pyramid_bimt.models import User
     from pyramid_bimt.views.auth import LoginAs
     context = User.by_email('*****@*****.**')
     request = testing.DummyRequest(layout_manager=mock.Mock())
     request.user = context
     resp = LoginAs(request)()
     self.assertEqual(resp['title'], 'Login as user')
     self.assertIn('Login as user', resp['form'])
Exemple #5
0
 def test_view_csrf_token(self):
     from pyramid_bimt.models import User
     from pyramid_bimt.views.auth import LoginAs
     context = User.by_email('*****@*****.**')
     request = testing.DummyRequest(layout_manager=mock.Mock())
     request.user = context
     view = LoginAs(request)
     csrf_token_field = view.schema.get('csrf_token')
     self.assertIsNotNone(csrf_token_field)
     self.assertEqual(csrf_token_field.title, 'Csrf Token')
Exemple #6
0
    def test_loginas_view_submit_success_as_user(self):
        from pyramid_bimt.models import User
        from pyramid_bimt.models import Group
        from pyramid_bimt.views.auth import LoginAs

        Session.add(
            User(email='*****@*****.**', groups=[
                Group.by_name('enabled'),
            ]))

        context = User.by_email('*****@*****.**')
        context.groups.append(Group.by_name('impersonators'))
        request = testing.DummyRequest(
            layout_manager=mock.Mock(),
            session=mock.Mock(),
        )
        form_values = {'email': '*****@*****.**'}
        request.user = context
        view = LoginAs(request)
        resp = view.login_as_success(form_values)
        self.assertEqual(resp.location, 'http://example.com')
        request.session.flash.assert_called_once_with(
            u'You have successfully logged in as user "*****@*****.**".')