Skip to content

Instantly share code, notes, and snippets.

@zhangchunlin
Last active October 9, 2019 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangchunlin/402a15ee39234502a4f0b91b0672df67 to your computer and use it in GitHub Desktop.
Save zhangchunlin/402a15ee39234502a4f0b91b0672df67 to your computer and use it in GitHub Desktop.
import os
from uliweb import manage, models
from uliweb.manage import make_simple_application
os.chdir('demo')
manage.call('uliweb syncdb -v')
manage.call('uliweb dbinit -v')
def test_apijson_get():
"""
>>> app = make_simple_application(project_dir='.')
>>> from uliweb import is_in_web
>>> from uliweb.utils.test import client
>>> c = client('.')
>>> data ='''{
... "user":{
... "@role":"OWNER"
... }
... }'''
>>> r = c.post('/apijson/get',data=data)
>>> print(r.data)
{}
"""
User = get_model('user')
def pre_call(request):
user = User.get(int(user_id))
request.user = user
settings.set_var('GENERIC/X_SENDFILE', False)
handler = application.handler()
begin = time.time()
r = handler.get(str(url), pre_call=pre_call, middlewares=[])
#disable direct_passthrough change for werkzeug 0.9.1
r.direct_passthrough = False
fname = functions.filename_convert(filename, UUIDFilenameConverter)
real_fname = os.path.join(settings.get_var('GENERIC/DOWNLOAD_DIR'), fname)
path = os.path.dirname(real_fname)
if not os.path.exists(path):
os.makedirs(path)
with open(real_fname, 'wb') as f:
f.write(r.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment