| 688 | |
| 689 | |
| 690 | def test_complex_routing_rules(): |
| 691 | m = r.Map( |
| 692 | [ |
| 693 | r.Rule("/", endpoint="index"), |
| 694 | r.Rule("/<int:blub>", endpoint="an_int"), |
| 695 | r.Rule("/<blub>", endpoint="a_string"), |
| 696 | r.Rule("/foo/", endpoint="nested"), |
| 697 | r.Rule("/foobar/", endpoint="nestedbar"), |
| 698 | r.Rule("/foo/<path:testing>/", endpoint="nested_show"), |
| 699 | r.Rule("/foo/<path:testing>/edit", endpoint="nested_edit"), |
| 700 | r.Rule("/users/", endpoint="users", defaults={"page": 1}), |
| 701 | r.Rule("/users/page/<int:page>", endpoint="users"), |
| 702 | r.Rule("/foox", endpoint="foox"), |
| 703 | r.Rule("/<path:bar>/<path:blub>", endpoint="barx_path_path"), |
| 704 | ] |
| 705 | ) |
| 706 | a = m.bind("example.com") |
| 707 | |
| 708 | assert a.match("/") == ("index", {}) |
| 709 | assert a.match("/42") == ("an_int", {"blub": 42}) |
| 710 | assert a.match("/blub") == ("a_string", {"blub": "blub"}) |
| 711 | assert a.match("/foo/") == ("nested", {}) |
| 712 | assert a.match("/foobar/") == ("nestedbar", {}) |
| 713 | assert a.match("/foo/1/2/3/") == ("nested_show", {"testing": "1/2/3"}) |
| 714 | assert a.match("/foo/1/2/3/edit") == ("nested_edit", {"testing": "1/2/3"}) |
| 715 | assert a.match("/users/") == ("users", {"page": 1}) |
| 716 | assert a.match("/users/page/2") == ("users", {"page": 2}) |
| 717 | assert a.match("/foox") == ("foox", {}) |
| 718 | assert a.match("/1/2/3") == ("barx_path_path", {"bar": "1", "blub": "2/3"}) |
| 719 | |
| 720 | assert a.build("index") == "/" |
| 721 | assert a.build("an_int", {"blub": 42}) == "/42" |
| 722 | assert a.build("a_string", {"blub": "test"}) == "/test" |
| 723 | assert a.build("nested") == "/foo/" |
| 724 | assert a.build("nestedbar") == "/foobar/" |
| 725 | assert a.build("nested_show", {"testing": "1/2/3"}) == "/foo/1/2/3/" |
| 726 | assert a.build("nested_edit", {"testing": "1/2/3"}) == "/foo/1/2/3/edit" |
| 727 | assert a.build("users", {"page": 1}) == "/users/" |
| 728 | assert a.build("users", {"page": 2}) == "/users/page/2" |
| 729 | assert a.build("foox") == "/foox" |
| 730 | assert a.build("barx_path_path", {"bar": "1", "blub": "2/3"}) == "/1/2/3" |
| 731 | |
| 732 | |
| 733 | def test_default_converters(): |