python unittest - Unit test a Flask session - cannot reproduce failure with session_transaction -


i testing flask application (flask 0.9), , in particular have session fixture run in documented-way, being (as understand it):

from flask import flask, session app = flask(__name__)  @app.route('/', methods=['post']) def m():     logging.error(session) # expect {'x': 1}     return ""  app.test_request_context() trc:   app.test_client() c:     c.session_transaction() sess:       sess['x'] = 1     c.post() 

this works expected, output being this:

error:root:<securecookiesession {'x': 1}> 

unfortunately encountering unexpected result session data not set in endpoint function, i.e. output this:

error:root:<securecookiesession {}> 

this issue exhibits when run unit testing framework. stands, unable reproduce problem degenerate case, though have made substantial effort with gist of of effort here. salient points being have included itsdangerous , google app engine testbed, expecting maybe 1 of them have been cause.

on own system have gone further gist, , replicated unit test framework trying isolate this. likewise, have removed ever-increasing amounts of relevant code testing framework. point, unable think of differences between degenerate case , stripped-down framework influence outcome. have traversed c.post() call in pdb try eek out cause of malignity, have yet glean useful insight.

which say, grateful little direction or suggestion issue may lie. possibly influencing werkzeug context in such way session_transaction not being honoured?

in case, restricting cookies specific domain automatically loading configuration file. updating configuration on-the-fly, able cookies work while unit testing. setting session_cookie_domain property none, domains (namely localhost) able set sessions.

app.config.update(                                                          session_cookie_domain = none                                                 ) 

you may want fiddle around configuration settings described under configuration handling in docs.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -