Use HTTPStatus in flask test server
This commit is contained in:
parent
81acba4700
commit
3d5bba9cff
@ -32,6 +32,7 @@ import time
|
|||||||
import signal
|
import signal
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
from http import HTTPStatus
|
||||||
|
|
||||||
import cheroot.wsgi
|
import cheroot.wsgi
|
||||||
import flask
|
import flask
|
||||||
@ -112,7 +113,7 @@ def redirect_n_times(n):
|
|||||||
def relative_redirect():
|
def relative_redirect():
|
||||||
"""302 Redirect once."""
|
"""302 Redirect once."""
|
||||||
response = app.make_response('')
|
response = app.make_response('')
|
||||||
response.status_code = 302
|
response.status_code = HTTPStatus.FOUND
|
||||||
response.headers['Location'] = flask.url_for('root')
|
response.headers['Location'] = flask.url_for('root')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ def relative_redirect():
|
|||||||
def absolute_redirect():
|
def absolute_redirect():
|
||||||
"""302 Redirect once."""
|
"""302 Redirect once."""
|
||||||
response = app.make_response('')
|
response = app.make_response('')
|
||||||
response.status_code = 302
|
response.status_code = HTTPStatus.FOUND
|
||||||
response.headers['Location'] = flask.url_for('root', _external=True)
|
response.headers['Location'] = flask.url_for('root', _external=True)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ def redirect_to():
|
|||||||
# werkzeug from "fixing" the URL. This endpoint should set the Location
|
# werkzeug from "fixing" the URL. This endpoint should set the Location
|
||||||
# header to the exact string supplied.
|
# header to the exact string supplied.
|
||||||
response = app.make_response('')
|
response = app.make_response('')
|
||||||
response.status_code = 302
|
response.status_code = HTTPStatus.FOUND
|
||||||
response.headers['Location'] = flask.request.args['url'].encode('utf-8')
|
response.headers['Location'] = flask.request.args['url'].encode('utf-8')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ def content_size():
|
|||||||
response = flask.Response(generate_bytes(), headers={
|
response = flask.Response(generate_bytes(), headers={
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
})
|
})
|
||||||
response.status_code = 200
|
response.status_code = HTTPStatus.OK
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ def twenty_mb():
|
|||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
"Content-Length": str(20 * 1024 * 1024),
|
"Content-Length": str(20 * 1024 * 1024),
|
||||||
})
|
})
|
||||||
response.status_code = 200
|
response.status_code = HTTPStatus.OK
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ def internal_error_attachment():
|
|||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
"Content-Disposition": 'inline; filename="attachment.jpg"',
|
"Content-Disposition": 'inline; filename="attachment.jpg"',
|
||||||
})
|
})
|
||||||
response.status_code = 500
|
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -199,7 +200,7 @@ def basic_auth(user='user', passwd='passwd'):
|
|||||||
auth = flask.request.authorization
|
auth = flask.request.authorization
|
||||||
if not auth or auth.username != user or auth.password != passwd:
|
if not auth or auth.username != user or auth.password != passwd:
|
||||||
r = flask.make_response()
|
r = flask.make_response()
|
||||||
r.status_code = 401
|
r.status_code = HTTPStatus.UNAUTHORIZED
|
||||||
r.headers = {'WWW-Authenticate': 'Basic realm="Fake Realm"'}
|
r.headers = {'WWW-Authenticate': 'Basic realm="Fake Realm"'}
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@ -222,14 +223,14 @@ def drip():
|
|||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
"Content-Length": str(numbytes),
|
"Content-Length": str(numbytes),
|
||||||
})
|
})
|
||||||
response.status_code = 200
|
response.status_code = HTTPStatus.OK
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.route('/404')
|
@app.route('/404')
|
||||||
def status_404():
|
def status_404():
|
||||||
r = flask.make_response()
|
r = flask.make_response()
|
||||||
r.status_code = 404
|
r.status_code = HTTPStatus.NOT_FOUND
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user