python - Pyramid authentication testing with webtest -


i configured pyramid app in order have user object attached request once has been authenticated following official tutorial. far good... while works , can test using browser, don't understand why in webtest tests user not attached request. configured test class in way:

from my_pyramid_app import main make_app webtest.app import testapp pyramid import testing  class logintestcase(testcase):        def setup(self):         self.config = testing.setup()         self.app = testapp(make_app({})) 

and in test:

# submit valid login data /login , expect redirect "next" response = self.app.post('/login', data, status=302) redirect = response.follow() 

it works expected, user gets authenticated , redirected path specified in "next", redirect.request not contain user. why? should do?

ps. documentation of webtest says:

the best way simulate authentication if application looks in environ['remote_user'] see if authenticated. can set value, like:

app.get('/secret', extra_environ=dict(remote_user='bob'))

but sounds demential me :/ (i mean if define variable manually sense of test?!)

both webtest , pyramid use webob doesn't mean pyramid's request same object webtest's response.request

the immutable object shared between webtest , tested application environ dictionary.

this mean may able retrieve user if store in request.environ key 'myapp.user' (dot , lowercase important, see pep333).


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -