def test_root_path_build() -> None: map_ = Map() map_.add(Rule("/", {"GET"}, "http")) adapter = map_.bind_to_request(False, "", "GET", "/", b"", False, "/rooti") assert adapter.build("http", method="GET") == "/rooti/" # Relative root_path case adapter = map_.bind_to_request(False, "", "GET", "/", b"", False, "rooti") assert adapter.build("http", method="GET") == "/rooti/"
def _test_strict_slashes(map_: Map) -> None: adapter = map_.bind_to_request('http', 'localhost', 'POST', '/path/') with pytest.raises(MethodNotAllowed): adapter.match() adapter = map_.bind_to_request('http', 'localhost', 'GET', '/path') try: adapter.match() except RedirectRequired as error: assert error.redirect_path == '/path/'
def test_method_not_allowed_error(basic_map: Map) -> None: adapter = basic_map.bind_to_request('http', '', 'GET', '/') try: adapter.match() except Exception as error: assert isinstance(error, MethodNotAllowed) assert error.allowed_methods == {'DELETE', 'POST'}
def test_method_not_allowed_error(basic_map: Map) -> None: adapter = basic_map.bind_to_request(False, "", "GET", "/", b"", False, "") try: adapter.match() except Exception as error: assert isinstance(error, MethodNotAllowed) assert error.allowed_methods == {"DELETE", "POST"}
def test_websocket_and_method_not_allowed() -> None: map_ = Map() map_.add(Rule("/ws/", {"GET"}, "websocket", is_websocket=True)) map_.add(Rule("/ws/", {"POST"}, "post")) adapter = map_.bind_to_request(False, "", "PUT", "/ws/", b"", False, "") with pytest.raises(MethodNotAllowed): adapter.match()
def test_websocket_bad_request(websocket: bool) -> None: map_ = Map() map_.add(Rule("/ws/", {"GET"}, "websocket", is_websocket=websocket)) adapter = map_.bind_to_request(False, "", "GET", "/ws/", b"", not websocket, "") with pytest.raises(BadRequest): adapter.match()
def _test_no_match(map_: Map, path: str, method: str, root_path: str = "") -> None: adapter = map_.bind_to_request(False, "", method, path, b"", False, root_path) with pytest.raises(NotFound): adapter.match()
def _test_match( map_: Map, path: str, method: str, expected: Tuple[Rule, Dict[str, Any]], host: str = '', ) -> None: adapter = map_.bind_to_request('http', host, method, path) assert adapter.match() == expected
def _test_match( map_: Map, path: str, method: str, expected: Tuple[Rule, Dict[str, Any]], host: str = '', websocket: bool = False, ) -> None: adapter = map_.bind_to_request(False, host, method, path, b'', websocket) assert adapter.match() == expected
def _test_match_redirect(map_: Map, path: str, method: str, redirect_path: str, query_string: bytes = b"", host: str = "") -> None: adapter = map_.bind_to_request(False, host, method, path, query_string, False, "") with pytest.raises(RedirectRequired) as error: adapter.match() assert error.value.redirect_path == f"http://{host}{redirect_path}"
def _test_match_redirect( map_: Map, path: str, method: str, redirect_path: str, query_string: bytes = b'', host: str = '', ) -> None: adapter = map_.bind_to_request('http', host, method, path, query_string) with pytest.raises(RedirectRequired) as error: adapter.match() assert error.value.redirect_path == redirect_path
def _test_strict_slashes(map_: Map) -> None: adapter = map_.bind_to_request('http', '', 'POST', '/path/') with pytest.raises(MethodNotAllowed): adapter.match() _test_match_redirect(map_, '/path', 'GET', '/path/')
def _test_no_match(map_: Map, path: str, method: str) -> None: adapter = map_.bind_to_request('http', '', method, path) with pytest.raises(NotFound): adapter.match()
def _test_match_redirect(map_: Map, path: str, method: str, redirect_path: str) -> None: adapter = map_.bind_to_request('http', '', method, path) with pytest.raises(RedirectRequired) as error: adapter.match() assert error.value.redirect_path == redirect_path
def _test_strict_slashes(map_: Map) -> None: adapter = map_.bind_to_request(False, "", "POST", "/path/", b"", False, "") with pytest.raises(MethodNotAllowed): adapter.match() _test_match_redirect(map_, "/path", "GET", "/path/")