Best Python code snippet using localstack_python
test_edge.py
Source:test_edge.py
...294 )295 def test_forward_raw_path(self, monkeypatch):296 class MyListener(ProxyListener):297 def forward_request(self, method, path, data, headers):298 _path = get_full_raw_path(quart_request)299 return {"method": method, "path": _path}300 # start listener and configure EDGE_FORWARD_URL301 port = get_free_tcp_port()302 forward_url = f"http://localhost:{port}"303 listener = MyListener()304 proxy = start_proxy_server(port, update_listener=listener, use_ssl=True)305 monkeypatch.setattr(config, "EDGE_FORWARD_URL", forward_url)306 # run test request, assert that raw request path is forwarded307 test_arn = "arn:aws:test:resource/test"308 raw_path = f"/test/{urllib.parse.quote(test_arn)}/bar?q1=foo&q2=bar"309 url = f"{config.get_edge_url()}{raw_path}"310 response = requests.get(url)311 expected = {"method": "GET", "path": raw_path}312 assert json.loads(to_str(response.content)) == expected...
request.py
Source:request.py
...160 if hasattr(request, "scope"):161 # quart request raw_path comes as bytes, and without the query part162 return request.scope.get("raw_path", request.path).decode("utf-8")163 raise ValueError("cannot extract raw path from request object %s" % request)164def get_full_raw_path(request) -> str:165 """166 Returns the full raw request path (with original URL encoding), including the query string.167 This is _not_ equal to request.url, since there the path section would be url-encoded while the query part will be168 (partly) url-decoded.169 """170 query_str = f"?{strings.to_str(request.query_string)}" if request.query_string else ""171 raw_path = f"{get_raw_path(request)}{query_str}"172 return raw_path173def restore_payload(request: Request) -> bytes:174 """175 This method takes a request and restores the original payload from it even after it has been consumed. A werkzeug176 request consumes form/multipart data from the stream, and here we are serializing it back to a request a client177 could make . This is a useful method to have when we are proxying requests, i.e., create outgoing requests from178 incoming requests that were subject to previous parsing....
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!