Last active
October 9, 2019 03:54
-
-
Save zhangchunlin/402a15ee39234502a4f0b91b0672df67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{} | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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