(self)
| 181 | |
| 182 | class RuleRouterTest(AsyncHTTPTestCase): |
| 183 | def get_app(self): |
| 184 | app = Application() |
| 185 | |
| 186 | def request_callable(request): |
| 187 | request.connection.write_headers( |
| 188 | ResponseStartLine("HTTP/1.1", 200, "OK"), |
| 189 | HTTPHeaders({"Content-Length": "2"}), |
| 190 | ) |
| 191 | request.connection.write(b"OK") |
| 192 | request.connection.finish() |
| 193 | |
| 194 | router = CustomRouter() |
| 195 | router.add_routes( |
| 196 | {"/nested_handler": (app, _get_named_handler("nested_handler"))} |
| 197 | ) |
| 198 | |
| 199 | app.add_handlers( |
| 200 | ".*", |
| 201 | [ |
| 202 | ( |
| 203 | HostMatches("www.example.com"), |
| 204 | [ |
| 205 | ( |
| 206 | PathMatches("/first_handler"), |
| 207 | "tornado.test.routing_test.SecondHandler", |
| 208 | {}, |
| 209 | "second_handler", |
| 210 | ) |
| 211 | ], |
| 212 | ), |
| 213 | Rule(PathMatches("/.*handler"), router), |
| 214 | Rule(PathMatches("/first_handler"), FirstHandler, name="first_handler"), |
| 215 | Rule(PathMatches("/request_callable"), request_callable), |
| 216 | ("/connection_delegate", ConnectionDelegate()), |
| 217 | ], |
| 218 | ) |
| 219 | |
| 220 | return app |
| 221 | |
| 222 | def test_rule_based_router(self): |
| 223 | response = self.fetch("/first_handler") |
nothing calls this directly
no test coverage detected