Reformatted code to use spaces instead of tabs

This commit is contained in:
Channel Cat
2016-10-14 19:53:49 -07:00
parent 67db0bcbf3
commit 254861bc37
21 changed files with 344 additions and 266 deletions

View File

@@ -3,77 +3,80 @@ from sanic import Sanic
from sanic.response import json, text
from sanic.utils import sanic_endpoint_test
# ------------------------------------------------------------ #
# GET
# ------------------------------------------------------------ #
def test_sync():
app = Sanic('test_text')
app = Sanic('test_text')
@app.route('/')
def handler(request):
return text('Hello')
@app.route('/')
def handler(request):
return text('Hello')
request, response = sanic_endpoint_test(app)
request, response = sanic_endpoint_test(app)
assert response.text == 'Hello'
assert response.text == 'Hello'
def test_text():
app = Sanic('test_text')
app = Sanic('test_text')
@app.route('/')
async def handler(request):
return text('Hello')
@app.route('/')
async def handler(request):
return text('Hello')
request, response = sanic_endpoint_test(app)
request, response = sanic_endpoint_test(app)
assert response.text == 'Hello'
assert response.text == 'Hello'
def test_json():
app = Sanic('test_json')
app = Sanic('test_json')
@app.route('/')
async def handler(request):
return json({"test":True})
@app.route('/')
async def handler(request):
return json({"test": True})
request, response = sanic_endpoint_test(app)
request, response = sanic_endpoint_test(app)
try:
results = json_loads(response.text)
except:
raise ValueError("Expected JSON response but got '{}'".format(response))
try:
results = json_loads(response.text)
except:
raise ValueError("Expected JSON response but got '{}'".format(response))
assert results.get('test') == True
assert results.get('test') == True
def test_query_string():
app = Sanic('test_query_string')
app = Sanic('test_query_string')
@app.route('/')
async def handler(request):
return text('OK')
@app.route('/')
async def handler(request):
return text('OK')
request, response = sanic_endpoint_test(app, params=[("test1", 1), ("test2", "false"), ("test2", "true")])
request, response = sanic_endpoint_test(app, params=[("test1", 1), ("test2", "false"), ("test2", "true")])
assert request.args.get('test1') == '1'
assert request.args.get('test2') == 'false'
assert request.args.get('test1') == '1'
assert request.args.get('test2') == 'false'
# ------------------------------------------------------------ #
# POST
# ------------------------------------------------------------ #
def test_post_json():
app = Sanic('test_post_json')
app = Sanic('test_post_json')
@app.route('/')
async def handler(request):
return text('OK')
@app.route('/')
async def handler(request):
return text('OK')
payload = {'test': 'OK'}
headers = {'content-type': 'application/json'}
payload = {'test': 'OK'}
headers = {'content-type': 'application/json'}
request, response = sanic_endpoint_test(app, data=json_dumps(payload), headers=headers)
request, response = sanic_endpoint_test(app, data=json_dumps(payload), headers=headers)
assert request.json.get('test') == 'OK'
assert response.text == 'OK'
assert request.json.get('test') == 'OK'
assert response.text == 'OK'