| 270 | |
| 271 | |
| 272 | def test_basic_building(): |
| 273 | map = r.Map( |
| 274 | [ |
| 275 | r.Rule("/", endpoint="index"), |
| 276 | r.Rule("/foo", endpoint="foo"), |
| 277 | r.Rule("/bar/<baz>", endpoint="bar"), |
| 278 | r.Rule("/bar/<int:bazi>", endpoint="bari"), |
| 279 | r.Rule("/bar/<float:bazf>", endpoint="barf"), |
| 280 | r.Rule("/bar/<path:bazp>", endpoint="barp"), |
| 281 | r.Rule("/hehe", endpoint="blah", subdomain="blah"), |
| 282 | r.Rule("/ws", endpoint="ws", websocket=True), |
| 283 | ] |
| 284 | ) |
| 285 | adapter = map.bind("example.org", "/", subdomain="blah") |
| 286 | |
| 287 | assert adapter.build("index", {}) == "http://example.org/" |
| 288 | assert adapter.build("foo", {}) == "http://example.org/foo" |
| 289 | assert adapter.build("bar", {"baz": "blub"}) == "http://example.org/bar/blub" |
| 290 | assert adapter.build("bari", {"bazi": 50}) == "http://example.org/bar/50" |
| 291 | assert adapter.build("barf", {"bazf": 0.815}) == "http://example.org/bar/0.815" |
| 292 | assert adapter.build("barp", {"bazp": "la/di"}) == "http://example.org/bar/la/di" |
| 293 | assert adapter.build("blah", {}) == "/hehe" |
| 294 | pytest.raises(r.BuildError, lambda: adapter.build("urks")) |
| 295 | |
| 296 | adapter = map.bind("example.org", "/test", subdomain="blah") |
| 297 | assert adapter.build("index", {}) == "http://example.org/test/" |
| 298 | assert adapter.build("foo", {}) == "http://example.org/test/foo" |
| 299 | assert adapter.build("bar", {"baz": "blub"}) == "http://example.org/test/bar/blub" |
| 300 | assert adapter.build("bari", {"bazi": 50}) == "http://example.org/test/bar/50" |
| 301 | assert adapter.build("barf", {"bazf": 0.815}) == "http://example.org/test/bar/0.815" |
| 302 | assert ( |
| 303 | adapter.build("barp", {"bazp": "la/di"}) == "http://example.org/test/bar/la/di" |
| 304 | ) |
| 305 | assert adapter.build("blah", {}) == "/test/hehe" |
| 306 | |
| 307 | adapter = map.bind("example.org") |
| 308 | assert adapter.build("foo", {}) == "/foo" |
| 309 | assert adapter.build("foo", {}, force_external=True) == "http://example.org/foo" |
| 310 | adapter = map.bind("example.org", url_scheme="") |
| 311 | assert adapter.build("foo", {}) == "/foo" |
| 312 | assert adapter.build("foo", {}, force_external=True) == "//example.org/foo" |
| 313 | assert ( |
| 314 | adapter.build("foo", {}, url_scheme="https", force_external=True) |
| 315 | == "https://example.org/foo" |
| 316 | ) |
| 317 | |
| 318 | adapter = map.bind("example.org", url_scheme="ws") |
| 319 | assert adapter.build("ws", {}) == "ws://example.org/ws" |
| 320 | assert adapter.build("foo", {}, force_external=True) == "http://example.org/foo" |
| 321 | assert adapter.build("foo", {}) == "/foo" |
| 322 | assert adapter.build("ws", {}, url_scheme="https") == "wss://example.org/ws" |
| 323 | |
| 324 | |
| 325 | def test_long_build(): |