Example #1
0
    def factory(name, **content):
        channel_layer = ChannelLayer()
        message = Message(content, name, channel_layer)
        settings.SESSION_FILE_PATH = str(tmpdir)
        message.channel_session = SessionStore()

        return message
Example #2
0
    def __init__(self):
        self.last_message = None

        self.channel_layer = ChannelLayer()
        self.factory = HTTPFactory(self.channel_layer, send_channel="test!")
        self.proto = self.factory.buildProtocol(('127.0.0.1', 0))
        self.transport = proto_helpers.StringTransport()
        self.proto.makeConnection(self.transport)
Example #3
0
 def setUp(self):
     """
     Make an in memory channel layer for testing
     """
     self.channel_layer = ChannelLayer()
     self.reply_channel = "http.response.test"
     self.start_response_value = None
     self.application = TestWsgiToAsgiAdapter(self.channel_layer)
Example #4
0
def _run_through_daphne(request, channel_name):
    """
    Returns Daphne's channel message for a given request.

    This helper requires a fair bit of scaffolding and can certainly be improved,
    but it works for now.
    """
    channel_layer = ChannelLayer()
    factory = HTTPFactory(channel_layer, send_channel="test!")
    proto = factory.buildProtocol(('127.0.0.1', 0))
    transport = proto_helpers.StringTransport()
    proto.makeConnection(transport)
    proto.dataReceived(request)
    _, message = channel_layer.receive([channel_name])
    return message, factory, transport
Example #5
0
class InMemoryLayerTests(ConformanceTestCase):
    channel_layer = ChannelLayer(expiry=1, group_expiry=2)
    expiry_delay = 1.1

    def test_group_message_eviction(self):
        """
        Tests that when messages expire, group expiry also occurs.
        """
        # Add things to a group and send a message that should expire
        self.channel_layer.group_add("tgme_group", "tgme_test")
        self.channel_layer.send_group("tgme_group", {"value": "blue"})
        # Wait message expiry plus a tiny bit (must sum to less than group expiry)
        time.sleep(1.2)
        # Send new message to group, ensure message never arrives
        self.channel_layer.send_group("tgme_group", {"value": "blue"})
        channel, message = self.channel_layer.receive_many(["tgme_test"])
        self.assertIs(channel, None)
        self.assertIs(message, None)
Example #6
0
 def setUp(self):
     """
     Make an in memory channel layer for testing
     """
     self.channel_layer = ChannelLayer()
     self.make_message = lambda m, c: Message(m, c, self.channel_layer)
Example #7
0
 def setUp(self):
     self.channel_layer = ChannelLayer()
     self.factory = HTTPFactory(self.channel_layer)
     self.proto = self.factory.buildProtocol(('127.0.0.1', 0))
     self.tr = proto_helpers.StringTransport()
     self.proto.makeConnection(self.tr)
Example #8
0
from asgiref.inmemory import ChannelLayer
from asgiref.conformance import make_tests

channel_layer = ChannelLayer(expiry=1)
InMemoryTests = make_tests(channel_layer, expiry_delay=1.1)