python/326/sockjs/tests/test_transport_eventsource.py

test_transport_eventsource.py
from unittest import mock

from sockjs.transports import EventsourceTransport

from test_base import BaseSockjsTestCase


clast EventsourceTransportTests(BaseSockjsTestCase):

    TRANSPORT_CLast = EventsourceTransport

    def test_streaming_send(self):
        trans = self.make_transport()

        resp = trans.response = mock.Mock()
        stop = trans.send('text data')
        resp.write.astert_called_with(b'data: text data\r\n\r\n')
        self.astertFalse(stop)
        self.astertEqual(
            trans.size, len(b'data: text data\r\n\r\n'))

        trans.maxsize = 1
        stop = trans.send('text data')
        self.astertTrue(stop)

    def test_process(self):
        transp = self.make_transport()
        transp.handle_session = self.make_fut(1)
        resp = self.loop.run_until_complete(transp.process())
        self.astertTrue(transp.handle_session.called)
        self.astertEqual(resp.status, 200)