2021-07-05 09:51:36 +01:00
|
|
|
from sanic import Sanic, text
|
2021-06-16 13:13:55 +01:00
|
|
|
from sanic.constants import HTTP_METHODS, HTTPMethod
|
|
|
|
|
|
|
|
|
|
|
|
def test_string_compat():
|
|
|
|
assert "GET" == HTTPMethod.GET
|
|
|
|
assert "GET" in HTTP_METHODS
|
|
|
|
assert "get" == HTTPMethod.GET
|
|
|
|
assert "get" in HTTP_METHODS
|
|
|
|
|
|
|
|
assert HTTPMethod.GET.lower() == "get"
|
|
|
|
assert HTTPMethod.GET.upper() == "GET"
|
|
|
|
|
|
|
|
|
2021-07-05 09:51:36 +01:00
|
|
|
def test_use_in_routes(app: Sanic):
|
2021-06-16 13:13:55 +01:00
|
|
|
@app.route("/", methods=[HTTPMethod.GET, HTTPMethod.POST])
|
|
|
|
def handler(_):
|
|
|
|
return text("It works")
|
|
|
|
|
|
|
|
_, response = app.test_client.get("/")
|
|
|
|
assert response.status == 200
|
|
|
|
assert response.text == "It works"
|
|
|
|
|
|
|
|
_, response = app.test_client.post("/")
|
|
|
|
assert response.status == 200
|
|
|
|
assert response.text == "It works"
|