Beispiel #1
0
def test_param_parser_static_url():
    m = ASGIMiddlewareStaticFile(app=None, static_url="", static_root_paths=[])
    assert m.static_url == "/"

    m = ASGIMiddlewareStaticFile(app=None, static_url="/", static_root_paths=[])
    assert m.static_url == "/"

    m = ASGIMiddlewareStaticFile(app=None, static_url="/a", static_root_paths=[])
    assert m.static_url == "/a/"

    m = ASGIMiddlewareStaticFile(app=None, static_url="/a/", static_root_paths=[])
    assert m.static_url == "/a/"
async def test_cross_border_access():
    print(BASE_PATH)
    mw = ASGIMiddlewareStaticFile(None, "static", [BASE_PATH])

    assert isinstance(mw.locate_the_file("DEMO"), str)
    assert mw.locate_the_file("not_found") is None

    with pytest.raises(ValueError):
        mw.locate_the_file("../setup.py")
# project_name\project_name\asgi.py
"""
ASGI config for project_name project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

# to support static files
from asgi_middleware_static_file import ASGIMiddlewareStaticFile
from django.conf import settings
from django.core.asgi import get_asgi_application
from websocket.middleware import websockets

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project_name.settings')

application = get_asgi_application()
application = websockets(application)
application = ASGIMiddlewareStaticFile(
    application, static_url=settings.STATIC_URL, static_paths=[settings.STATIC_ROOT]
)
import os

from quart import Quart
from asgi_middleware_static_file import ASGIMiddlewareStaticFile

BASE_DIR = os.path.dirname(__name__)
STATIC_DIRS = [os.path.join(BASE_DIR, "example_static")]

app = Quart(__name__)


@app.route("/")
async def hello():
    return "hello"


app = ASGIMiddlewareStaticFile(app,
                               static_url="static",
                               static_root_paths=STATIC_DIRS)
import os

from asgiref.wsgi import WsgiToAsgi

from asgi_middleware_static_file import ASGIMiddlewareStaticFile

BASE_DIR = os.path.dirname(__name__)
STATIC_DIRS = [os.path.join(BASE_DIR, "example_static")]


def wsgi_app(environ, start_response):
    status = "200 OK"
    response_headers = [("Content-type", "text/plain")]
    start_response(status, response_headers)
    return ["Hello world!"]


app = ASGIMiddlewareStaticFile(WsgiToAsgi(wsgi_app),
                               static_url="static",
                               static_root_paths=STATIC_DIRS)