def test_handler_emptry_session(self): route = self.make_route() request = self.make_request( 'GET', '/sm/', match_info={'transport': 'websocket', 'session': ''}) res = self.loop.run_until_complete(route.handler(request)) self.assertIsInstance(res, web.HTTPNotFound)
def test_handler_unknown_transport(self): route = self.make_route() request = self.make_request( 'GET', '/sm/', match_info={'transport': 'unknown'}) res = self.loop.run_until_complete(route.handler(request)) self.assertIsInstance(res, web.HTTPNotFound)
def test_new_session_before_read(self): route = self.make_route() request = self.make_request( 'GET', '/sm/', match_info={ 'transport': 'xhr_send', 'session': 's1', 'server': '000'}) res = self.loop.run_until_complete(route.handler(request)) self.assertIsInstance(res, web.HTTPNotFound)
def test_fail_transport(self): request = self.make_request( 'GET', '/sm/', match_info={ 'transport': 'test', 'session': 'session', 'server': '000'}) params = [] class Transport: def __init__(self, manager, session, request): params.append((manager, session, request)) def process(self): raise Exception('Error') route = self.make_route(handlers={'test': (True, Transport)}) res = self.loop.run_until_complete(route.handler(request)) self.assertIsInstance(res, web.HTTPInternalServerError)
def test_release_session_for_failed_transport(self): request = self.make_request( 'GET', '/sm/', match_info={ 'transport': 'test', 'session': 's1', 'server': '000'}) class Transport: def __init__(self, manager, session, request): self.manager = manager self.session = session def process(self): yield from self.manager.acquire(self.session) raise Exception('Error') route = self.make_route(handlers={'test': (True, Transport)}) res = self.loop.run_until_complete(route.handler(request)) self.assertIsInstance(res, web.HTTPInternalServerError) s1 = route.manager['s1'] self.assertFalse(route.manager.is_acquired(s1))
def _test_transport(self): route = self.make_route() request = self.make_request( 'GET', '/sm/', match_info={ 'transport': 'xhr', 'session': 's1', 'server': '000'}) params = [] class Transport: def __init__(self, manager, session, request): params.append((manager, session, request)) def process(self): return web.HTTPOk() route = self.make_route(handlers={'test': (True, Transport)}) res = self.loop.run_until_complete(route.handler(request)) self.assertIsInstance(res, web.HTTPOk) self.assertEqual( params[0], (route.manager, route.manager['s1'], request))