Skip to content

Instantly share code, notes, and snippets.

@pgjones
Created February 12, 2017 16:00
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgjones/0bd192d3fae7f6dfadead178dbac0e1e to your computer and use it in GitHub Desktop.
Save pgjones/0bd192d3fae7f6dfadead178dbac0e1e to your computer and use it in GitHub Desktop.
Example of how to use the Flask `test_request_context` with a cookie set
@alanwilter
Copy link

alanwilter commented Jul 12, 2020

It did work!!! Thanks a lot.

from views import application, autocomplete
ctx = application.test_request_context(path='/login',method='POST', data={'user':'demo','password':'demo123'})
ctx.push()
application.preprocess_request()
query = 'ttll'
autocomplete.autocomplete(query,'gene').json

2020-07-12 13:11:44,523 INFO sqlalchemy.engine.base.Engine SELECT users."user" AS users_user, users.argon_password AS users_argon_password
FROM users
WHERE users."user" = %(user_1)s
2020-07-12 13:11:44,523 INFO sqlalchemy.engine.base.Engine {'user_1': 'demo'}
[D 200712 13:11:44 autocomplete:15] Autocomplete query 'ttll' and query type 'gene'
Out[5]:
['TTLL5',
 'ARPC4-TTLL3',
 'TTLL2',
 'TTLL7-IT1',
 'TTLL1',
 'TTLL10',
 'TTLL3',
 'TTLL6',
 'TTLL10-AS1',
 'TTLL4',
 'TTLL11',
 'TTLL13P',
 'TTLL12',
 'TTLL11-IT1',
 'TTLL8',
 'TTLL9',
 'TTLL7']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment