Пример #1
0
    def test_middleware_caching(self):
        """
        Tests that middleware is only loaded once
        and is successfully cached on the AsgiHandler class.
        """
        AsgiHandler()  # First Handler

        self.assertTrue(AsgiHandler._middleware_chain is not None)

        with patch("django.core.handlers.base.BaseHandler.load_middleware"
                   ) as super_function:
            AsgiHandler()  # Second Handler
            self.assertFalse(super_function.called)
Пример #2
0
    def test_middleware_caching(self):
        """
        Tests that middleware is only loaded once
        and is successfully cached on the AsgiHandler class.
        """

        scope = {
            "type": "http",
            "http_version": "1.1",
            "method": "GET",
            "path": "/test/",
        }

        AsgiHandler(scope)  # First Handler

        self.assertTrue(AsgiHandler._middleware_chain is not None)

        with patch("django.core.handlers.base.BaseHandler.load_middleware"
                   ) as super_function:
            AsgiHandler(scope)  # Second Handler
            self.assertFalse(super_function.called)
Пример #3
0
import os

from django import setup
# from channels.routing import get_default_application
from django.core.asgi import get_asgi_application

setup()
django_asgi_app = get_asgi_application()

from channels.auth import AuthMiddlewareStack
from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter, URLRouter

from chat import routing

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

application = ProtocolTypeRouter({
    "http":
    AsgiHandler(),
    "websocket":
    AuthMiddlewareStack(URLRouter(routing.websocket_urlpatterns)),
})
Пример #4
0
# chat_project/asgi.py
import os

from channels.auth import AuthMiddlewareStack

from channels.routing import ProtocolTypeRouter, URLRouter
import django
from channels.http import AsgiHandler
import chat.routing

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chat_project.settings')
django.setup()

application = ProtocolTypeRouter({
    "http": AsgiHandler(),
    "websocket": AuthMiddlewareStack(
        URLRouter(
            chat.routing.websocket_urlpatterns
        )
    ),
})
Пример #5
0
 def __init__(self, application_mapping):
     self.application_mapping = application_mapping
     if "http" not in self.application_mapping:
         warnings.warn(DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
         self.application_mapping["http"] = AsgiHandler()
Пример #6
0
import channels

from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter

if channels.__version__ < "3.0.0":
    channels_handler = AsgiHandler
else:
    channels_handler = AsgiHandler()

application = ProtocolTypeRouter({"http": channels_handler})
Пример #7
0
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from django.urls import path
import django
from channels.http import AsgiHandler
import main.routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE','Ecommerce.settings')
django.setup()



application= ProtocolTypeRouter(
    {
        'http': AsgiHandler(),
        'websocket': AuthMiddlewareStack(
            URLRouter(
                main.routing.websocket_urlpattern
            )
        ),
    }
)
Пример #8
0
def test_asgi_handler_deprecation():
    with pytest.warns(DeprecationWarning, match="AsgiHandler is deprecated"):
        AsgiHandler()
Пример #9
0
from django.conf.urls import url
from channels.routing import URLRouter
from channels.http import AsgiHandler
from channels.auth import AuthMiddlewareStack
import django_eventstream
from django.urls import include

urlpatterns = [
    url(r'^events/',
        AuthMiddlewareStack(URLRouter(django_eventstream.routing.urlpatterns)),
        {'channels': ['test']}),
    url(r'^objects/(?P<user_id>\d+)/events/',
        AuthMiddlewareStack(URLRouter(django_eventstream.routing.urlpatterns)),
        {'format-channels': ['user_{user_id}']}),
    url(r'', AsgiHandler()),
]
Пример #10
0
import django

from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter

from baserow.ws.routers import websocket_router


django.setup()


application = ProtocolTypeRouter({"http": AsgiHandler(), "websocket": websocket_router})
Пример #11
0
import os

import django
from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import re_path, path

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'svo.settings')
django.setup()

from airline.consumers import AirlineConsumer
from dispatcher.consumers import DispatcherConsumer

application = ProtocolTypeRouter(
    dict(http=URLRouter([
        re_path(r"", AsgiHandler()),
    ]),
         websocket=URLRouter([
             path("ws/airline/<int:airline_id>/", AirlineConsumer.as_asgi()),
             path("ws/dispatcher/", DispatcherConsumer.as_asgi())
         ])))