mirror of
https://github.com/django/daphne.git
synced 2025-07-14 18:02:17 +03:00
Remove inherited methods and relative imports (#163)
* Remove inherited methods from HttpClient * Using relative import in base of tests
This commit is contained in:
parent
05c41e9ad6
commit
8827063bf2
|
@ -4,10 +4,10 @@ import string
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from django.test.testcases import TestCase
|
from django.test.testcases import TestCase
|
||||||
from channels import DEFAULT_CHANNEL_LAYER
|
from .. import DEFAULT_CHANNEL_LAYER
|
||||||
from channels.routing import Router, include
|
from ..routing import Router, include
|
||||||
from channels.asgi import channel_layers, ChannelLayerWrapper
|
from ..asgi import channel_layers, ChannelLayerWrapper
|
||||||
from channels.message import Message
|
from ..message import Message
|
||||||
from asgiref.inmemory import ChannelLayer as InMemoryChannelLayer
|
from asgiref.inmemory import ChannelLayer as InMemoryChannelLayer
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@ import copy
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
from ..asgi import channel_layers
|
|
||||||
from ..message import Message
|
|
||||||
from ..sessions import session_for_reply_channel
|
from ..sessions import session_for_reply_channel
|
||||||
from .base import Client
|
from .base import Client
|
||||||
|
|
||||||
|
@ -59,23 +56,6 @@ class HttpClient(Client):
|
||||||
self._session = session_for_reply_channel(self.reply_channel)
|
self._session = session_for_reply_channel(self.reply_channel)
|
||||||
return self._session
|
return self._session
|
||||||
|
|
||||||
@property
|
|
||||||
def channel_layer(self):
|
|
||||||
"""Channel layer as lazy property"""
|
|
||||||
return channel_layers[self.alias]
|
|
||||||
|
|
||||||
def get_next_message(self, channel):
|
|
||||||
"""
|
|
||||||
Gets the next message that was sent to the channel during the test,
|
|
||||||
or None if no message is available.
|
|
||||||
|
|
||||||
If require is true, will fail the test if no message is received.
|
|
||||||
"""
|
|
||||||
recv_channel, content = channel_layers[self.alias].receive_many([channel])
|
|
||||||
if recv_channel is None:
|
|
||||||
return
|
|
||||||
return Message(content, recv_channel, channel_layers[self.alias])
|
|
||||||
|
|
||||||
def send(self, to, content={}):
|
def send(self, to, content={}):
|
||||||
"""
|
"""
|
||||||
Send a message to a channel.
|
Send a message to a channel.
|
||||||
|
@ -87,30 +67,6 @@ class HttpClient(Client):
|
||||||
content.setdefault('headers', self.headers)
|
content.setdefault('headers', self.headers)
|
||||||
self.channel_layer.send(to, content)
|
self.channel_layer.send(to, content)
|
||||||
|
|
||||||
def consume(self, channel):
|
|
||||||
"""
|
|
||||||
Get next message for channel name and run appointed consumer
|
|
||||||
"""
|
|
||||||
message = self.get_next_message(channel)
|
|
||||||
if message:
|
|
||||||
consumer, kwargs = self.channel_layer.router.match(message)
|
|
||||||
return consumer(message, **kwargs)
|
|
||||||
|
|
||||||
def send_and_consume(self, channel, content={}):
|
|
||||||
"""
|
|
||||||
Reproduce full live cycle of the message
|
|
||||||
"""
|
|
||||||
self.send(channel, content)
|
|
||||||
return self.consume(channel)
|
|
||||||
|
|
||||||
def receive(self):
|
|
||||||
"""
|
|
||||||
Get content of next message for reply channel if message exists
|
|
||||||
"""
|
|
||||||
message = self.get_next_message(self.reply_channel)
|
|
||||||
if message:
|
|
||||||
return message.content
|
|
||||||
|
|
||||||
def login(self, **credentials):
|
def login(self, **credentials):
|
||||||
"""
|
"""
|
||||||
Returns True if login is possible; False if the provided credentials
|
Returns True if login is possible; False if the provided credentials
|
||||||
|
|
Loading…
Reference in New Issue
Block a user