Skip to content

Commit

Permalink
Show http method in the connector builder test panel request tab (#20109
Browse files Browse the repository at this point in the history
)

Show http method in the connector builder test panel request tab
  • Loading branch information
clnoll authored Dec 6, 2022
1 parent 92ad0fd commit 4429968
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class HttpRequest(BaseModel):
parameters: The parameters of this HttpRequest [Optional].
body: The body of this HttpRequest [Optional].
headers: The headers of this HttpRequest [Optional].
http_method: The http_method of this HttpRequest.
"""

url: str
parameters: Optional[Dict[str, Any]] = None
body: Optional[Dict[str, Any]] = None
headers: Optional[Dict[str, Any]] = None
http_method: str

HttpRequest.update_forward_refs()
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ def _create_request_from_log_message(self, log_message: AirbyteLogMessage) -> Op
url = urlparse(request.get("url", ""))
full_path = f"{url.scheme}://{url.hostname}{url.path}" if url else ""
parameters = parse_qs(url.query) or None
return HttpRequest(url=full_path, headers=request.get("headers"), parameters=parameters, body=request.get("body"))
return HttpRequest(
url=full_path,
http_method=request.get("http_method", ""),
headers=request.get("headers"),
parameters=parameters,
body=request.get("body"),
)
except JSONDecodeError as error:
self.logger.warning(f"Failed to parse log message into request object with error: {error}")
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ components:
type: object
required:
- url
- http_method
properties:
url:
type: string
Expand All @@ -166,6 +167,10 @@ components:
headers:
type: object
description: The headers of the HTTP request, if any
http_method:
type: string
enum: ["GET", "POST", "PUT", "PATCH"]
description: The http method of the request ("GET", "POST", "PUT", or "PATCH")
HttpResponse:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,27 @@ def test_read_stream_returns_error_if_stream_does_not_exist():
"log_message, expected_request",
[
pytest.param(
'request:{"url": "https://nichirin.com/v1/swords?color=orange", "headers": {"field": "name"}, "body":{"key": "value"}}',
'request:{"url": "https://nichirin.com/v1/swords?color=orange", "http_method": "PUT", "headers": {"field": "name"}, "body":{"key": "value"}}',
HttpRequest(
url="https://nichirin.com/v1/swords", parameters={"color": ["orange"]}, headers={"field": "name"}, body={"key": "value"}
url="https://nichirin.com/v1/swords", parameters={"color": ["orange"]}, headers={"field": "name"}, body={"key": "value"},
http_method="PUT",
),
id="test_create_request_with_all_fields",
),
pytest.param(
'request:{"url": "https://nichirin.com/v1/swords?color=orange", "headers": {"field": "name"}}',
HttpRequest(url="https://nichirin.com/v1/swords", parameters={"color": ["orange"]}, headers={"field": "name"}),
'request:{"url": "https://nichirin.com/v1/swords?color=orange", "http_method": "GET", "headers": {"field": "name"}}',
HttpRequest(url="https://nichirin.com/v1/swords", parameters={"color": ["orange"]}, headers={"field": "name"},
http_method="GET"),
id="test_create_request_with_no_body",
),
pytest.param(
'request:{"url": "https://nichirin.com/v1/swords?color=orange", "body":{"key": "value"}}',
HttpRequest(url="https://nichirin.com/v1/swords", parameters={"color": ["orange"]}, body={"key": "value"}),
'request:{"url": "https://nichirin.com/v1/swords?color=orange", "http_method": "PUT", "body":{"key": "value"}}',
HttpRequest(url="https://nichirin.com/v1/swords", parameters={"color": ["orange"]}, body={"key": "value"}, http_method="PUT"),
id="test_create_request_with_no_headers",
),
pytest.param(
'request:{"url": "https://nichirin.com/v1/swords", "headers": {"field": "name"}, "body":{"key": "value"}}',
HttpRequest(url="https://nichirin.com/v1/swords", headers={"field": "name"}, body={"key": "value"}),
'request:{"url": "https://nichirin.com/v1/swords", "http_method": "PUT", "headers": {"field": "name"}, "body":{"key": "value"}}',
HttpRequest(url="https://nichirin.com/v1/swords", headers={"field": "name"}, body={"key": "value"}, http_method="PUT"),
id="test_create_request_with_no_parameters",
),
pytest.param("request:{invalid_json: }", None, id="test_invalid_json_still_does_not_crash"),
Expand Down

0 comments on commit 4429968

Please sign in to comment.