-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Only unquote on string casts * line length * Add unit tests * squash * Fix typing issue
- Loading branch information
Showing
4 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from unittest.mock import Mock | ||
|
||
from sanic_routing import BaseRouter | ||
|
||
|
||
class Router(BaseRouter): | ||
def get(self, path, method, extra=None): | ||
return self.resolve(path=path, method=method, extra=extra) | ||
|
||
|
||
def test_no_unquote(): | ||
handler = Mock(return_value=123) | ||
|
||
router = Router() | ||
router.add("/<foo>/<bar>", methods=["GET"], handler=handler, unquote=False) | ||
router.finalize() | ||
|
||
_, handler, params = router.get("/%F0%9F%98%8E/sunglasses", "GET") | ||
assert params == {"bar": "sunglasses", "foo": "%F0%9F%98%8E"} | ||
|
||
_, handler, params = router.get("/😎/sunglasses", "GET") | ||
assert params == {"bar": "sunglasses", "foo": "😎"} | ||
|
||
|
||
def test_unquote(): | ||
handler = Mock(return_value=123) | ||
|
||
router = Router() | ||
router.add("/<foo>/<bar>", methods=["GET"], handler=handler, unquote=True) | ||
router.finalize() | ||
|
||
_, handler, params = router.get("/%F0%9F%98%8E/sunglasses", "GET") | ||
assert params == {"bar": "sunglasses", "foo": "😎"} | ||
|
||
_, handler, params = router.get("/😎/sunglasses", "GET") | ||
assert params == {"bar": "sunglasses", "foo": "😎"} | ||
|
||
|
||
def test_unquote_non_string(): | ||
handler = Mock(return_value=123) | ||
|
||
router = Router() | ||
router.add( | ||
"/<foo>/<bar:int>", methods=["GET"], handler=handler, unquote=True | ||
) | ||
router.finalize() | ||
|
||
_, handler, params = router.get("/%F0%9F%98%8E/123", "GET") | ||
assert params == {"bar": 123, "foo": "😎"} | ||
|
||
_, handler, params = router.get("/😎/123", "GET") | ||
assert params == {"bar": 123, "foo": "😎"} |