# Path: sockjs/transports/eventsource.py
# class EventsourceTransport(StreamingTransport):
#     async def send(self, text):
#         blob = "".join(("data: ", text, "\r\n\r\n")).encode(ENCODING)
#         await self.response.write(blob)
# 
#         self.size += len(blob)
#         if self.size > self.maxsize:
#             return True
#         else:
#             return False
# 
#     async def process(self):
#         headers = (
#             (hdrs.CONTENT_TYPE, "text/event-stream"),
#             (hdrs.CACHE_CONTROL, CACHE_CONTROL),
#         )
#         headers += session_cookie(self.request)
# 
#         # open sequence (sockjs protocol)
#         resp = self.response = web.StreamResponse(headers=headers)
#         await resp.prepare(self.request)
#         await resp.write(b"\r\n")
# 
#         # handle session
#         await self.handle_session()
# 
#         return resp


from unittest import mock
from aiohttp import web
from aiohttp.test_utils import make_mocked_coro
from sockjs.transports import EventsourceTransport
import pytest




@pytest.fixture
def make_transport(make_manager, make_request, make_handler, make_fut):
    def maker(method="GET", path="/", query_params={}):
        handler = make_handler(None)
        manager = make_manager(handler)
        request = make_request(method, path, query_params=query_params)
        request.app.freeze()
        session = manager.get("TestSessionEventSource", create=True, request=request)

# Path: sockjs/transports/eventsource.py
# class EventsourceTransport(StreamingTransport):
#     async def send(self, text):
#         blob = "".join(("data: ", text, "\r\n\r\n")).encode(ENCODING)
#         await self.response.write(blob)
# 
#         self.size += len(blob)
#         if self.size > self.maxsize:
#             return True
#         else:
#             return False
# 
#     async def process(self):
#         headers = (
#             (hdrs.CONTENT_TYPE, "text/event-stream"),
#             (hdrs.CACHE_CONTROL, CACHE_CONTROL),
#         )
#         headers += session_cookie(self.request)
# 
#         # open sequence (sockjs protocol)
#         resp = self.response = web.StreamResponse(headers=headers)
#         await resp.prepare(self.request)
#         await resp.write(b"\r\n")
# 
#         # handle session
#         await self.handle_session()
# 
#         return resp


# Path: tests/test_transport_eventsource.py
from unittest import mock
from aiohttp import web
from aiohttp.test_utils import make_mocked_coro
from sockjs.transports import EventsourceTransport
import pytest





@pytest.fixture
def make_transport(make_manager, make_request, make_handler, make_fut):
    def maker(method="GET", path="/", query_params={}):
        handler = make_handler(None)
        manager = make_manager(handler)
        request = make_request(method, path, query_params=query_params)
        request.app.freeze()
        session = manager.get("TestSessionEventSource", create=True, request=request)

        return EventsourceTransport(manager, session, request)