def test_resource_adapter_resolve_bad_method(self): route = PlainRoute('POST', lambda req: None, None, '/path') self.router.register_route(route) resource = route.resource self.assertEqual((None, {'POST'}), self.loop.run_until_complete( resource.resolve('GET', '/path')))
def test_register_route_checks(self): self.assertRaises(AssertionError, self.router.register_route, object()) handler = self.make_handler() route = PlainRoute('GET', handler, 'test', '/handler/to/path') self.router.register_route(route) self.assertRaises(ValueError, self.router.register_route, route)
def test_resource_adapter_resolve_not_math(self): route = PlainRoute('GET', lambda req: None, None, '/path') self.router.register_route(route) resource = route.resource self.assertEqual((None, set()), self.loop.run_until_complete( resource.resolve('GET', '/another/path')))
def test_resource_adapter_resolve_wildcard(self): route = PlainRoute('*', lambda req: None, None, '/path') self.router.register_route(route) resource = route.resource match_info, allowed = self.loop.run_until_complete( resource.resolve('GET', '/path')) self.assertEqual(allowed, {'*'}) # TODO: expand wildcard self.assertIsNotNone(match_info)
def test_register_uncommon_http_methods(self): handler = self.make_handler() uncommon_http_methods = { 'PROPFIND', 'PROPPATCH', 'COPY', 'LOCK', 'UNLOCK' 'MOVE', 'SUBSCRIBE', 'UNSUBSCRIBE', 'NOTIFY' } for method in uncommon_http_methods: PlainRoute(method, handler, 'url', '/handler/to/path')
def test_register_route(self): handler = self.make_handler() route = PlainRoute('GET', handler, 'test', '/handler/to/path') self.router.register_route(route) req = self.make_request('GET', '/handler/to/path') info = self.loop.run_until_complete(self.router.resolve(req)) self.assertIsNotNone(info) self.assertEqual(0, len(info)) self.assertIs(route, info.route) self.assertIs(handler, info.handler) self.assertEqual(info.route.name, 'test')
def test_register_route(): @asyncio.coroutine def handler(request): return Response() route = PlainRoute('GET', handler, 'test', '/handler/to/path') router = UrlDispatcher() router.register_route(route) req = make_mocked_request('GET', '/handler/to/path') info = yield from router.resolve(req) assert info is not None assert 0 == len(info) assert route is info.route assert handler is info.handler assert info.route.name == 'test'
def test_plain_old_style_route_get_info(self): handler = self.make_handler() route = PlainRoute('GET', handler, 'test', '/handler/to/path') self.router.register_route(route) self.assertEqual(route.get_info(), {'path': '/handler/to/path'})
def test_plain_route_url(self): route = PlainRoute('GET', lambda req: None, None, '/path') self.router.register_route(route) self.assertEqual('/path?arg=1', route.url(query={'arg': 1}))
def test_deprecate_register_route(self): route = PlainRoute('GET', lambda req: None, None, '/path') with self.assertWarns(DeprecationWarning): self.router.register_route(route)
def test_resource_adapter_iter(self): route = PlainRoute('GET', lambda req: None, None, '/path') self.router.register_route(route) resource = route.resource self.assertEqual(1, len(resource)) self.assertEqual([route], list(resource))
def test_resource_adapter_not_match(self): route = PlainRoute('GET', lambda req: None, None, '/path') self.router.register_route(route) resource = route.resource self.assertIsNotNone(resource) self.assertIsNone(resource._route.match('/another/path'))
def test_plain_repr(self): handler = self.make_handler() route = PlainRoute('GET', handler, 'name', '/get/path') self.assertRegex(repr(route), r"<PlainRoute 'name' \[GET\] /get/path")