One way is to step through the whole login procedure. I.e. make sure your
test app is configured with a particular user (and password) in its user
db, then so something like::
res = self.app.get('/login')
login_form = res.forms['login-form']
login_form['username'] = 'someuser'
login_form['password'] = 'sekret'
res = login_form.submit().maybe_follow(status=200)
On Wed, Jun 17, 2015 at 10:39 AM, Winston Ferreira <[email protected]>
wrote:
> Hello,
>
> How do I set an authentication cookie with WebTest for unittesting?
>
> import unittest2 as unittest
> from webtest import TestApp
>
> from sisfest import main
>
>
> class MyTestCase(unittest.TestCase):
>
> def setUp(self):
> self.app = TestApp(main({}))
>
> def test_view_permission(self):
> self.app.get('/admin_only_url', status=200)
> # this will always return status=403
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.