2022-09-18 15:17:23 +01:00
|
|
|
import pytest
|
|
|
|
|
2021-07-05 09:51:36 +01:00
|
|
|
from sanic import Sanic, text
|
2022-09-18 15:17:23 +01:00
|
|
|
from sanic.application.constants import Mode, Server, ServerStage
|
2021-06-16 13:13:55 +01:00
|
|
|
from sanic.constants import HTTP_METHODS, HTTPMethod
|
|
|
|
|
|
|
|
|
2022-09-18 15:17:23 +01:00
|
|
|
@pytest.mark.parametrize("enum", (HTTPMethod, Server, Mode))
|
|
|
|
def test_string_compat(enum):
|
|
|
|
for key in enum.__members__.keys():
|
|
|
|
assert key.upper() == getattr(enum, key).upper()
|
|
|
|
assert key.lower() == getattr(enum, key).lower()
|
|
|
|
|
|
|
|
|
|
|
|
def test_http_methods():
|
|
|
|
for value in HTTPMethod.__members__.values():
|
|
|
|
assert value in HTTP_METHODS
|
|
|
|
|
2021-06-16 13:13:55 +01:00
|
|
|
|
2022-09-18 15:17:23 +01:00
|
|
|
def test_server_stage():
|
|
|
|
assert ServerStage.SERVING > ServerStage.PARTIAL > ServerStage.STOPPED
|
2021-06-16 13:13:55 +01:00
|
|
|
|
|
|
|
|
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"
|