Skip to content

Commit

Permalink
fixed tests w/ burnettk
Browse files Browse the repository at this point in the history
  • Loading branch information
jasquat committed Jun 12, 2024
1 parent 9d03aa6 commit 270c43c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: [ "3.10", "3.11" ]
python-version: ["3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand Down
6 changes: 5 additions & 1 deletion src/connector_http/http_request_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ def log(msg: str) -> None:
if self.params is not None:
arguments["params"] = self.params
if self.data is not None:
if not arguments["headers"].keys().include("Content-Type", "Content-type"):
if (
"Content-Type" not in self.headers
and "Content-type" not in self.headers
and "content-type" not in self.headers
):
arguments["headers"]["Content-Type"] = "application/json"
arguments["json"] = self.data
http_response = request_function(**arguments)
Expand Down
32 changes: 32 additions & 0 deletions tests/connector_http/unit/test_put_request_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@


class TestPutRequestV2:
expected_call_args = {
"url": "http://example.com",
"headers": {"Content-Type": "application/json"},
"auth": None,
"timeout": 300,
"json": {},
}

def test_put_html_from_url(self) -> None:
request = PutRequestV2(url="http://example.com")
return_html = "<html>Hey</html>"
Expand All @@ -15,6 +23,7 @@ def test_put_html_from_url(self) -> None:
mock_request.return_value.text = return_html
response = request.execute(None, {})
assert mock_request.call_count == 1
assert mock_request.call_args_list[0].kwargs == self.expected_call_args

assert response["command_response"]["body"] == {"raw_response": return_html}
assert response["command_response"]["http_status"] == 200
Expand All @@ -33,6 +42,7 @@ def test_put_json_from_url(self) -> None:
mock_request.return_value.text = json.dumps(return_json)
response = request.execute(None, {})
assert mock_request.call_count == 1
assert mock_request.call_args_list[0].kwargs == self.expected_call_args

assert response is not None
assert response["command_response"]["body"] == return_json
Expand All @@ -51,6 +61,7 @@ def test_put_can_handle_500(self, sleepless: Any) -> None:
mock_request.return_value.text = json.dumps(return_json)
response = request.execute(None, {})
assert mock_request.call_count == 1
assert mock_request.call_args_list[0].kwargs == self.expected_call_args

assert response is not None
assert response["command_response"]["body"] == return_json
Expand All @@ -59,3 +70,24 @@ def test_put_can_handle_500(self, sleepless: Any) -> None:
assert response["error"] is not None
assert response["spiff__logs"] is not None
assert len(response["spiff__logs"]) > 0

def test_put_does_not_change_content_type(self) -> None:
request = PutRequestV2(url="http://example.com", headers={"Content-Type": "application/xml"})
return_html = "<html>Hey</html>"
with patch("requests.put") as mock_request:
mock_request.return_value.status_code = 200
mock_request.return_value.ok = True
mock_request.return_value.text = return_html
response = request.execute(None, {})
assert mock_request.call_count == 1
assert mock_request.call_args_list[0].kwargs == {
**self.expected_call_args,
**{"headers": {"Content-Type": "application/xml"}},
}

assert response["command_response"]["body"] == {"raw_response": return_html}
assert response["command_response"]["http_status"] == 200
assert response["command_response"]["mimetype"] == "application/json"
assert response["error"] is None
assert response["spiff__logs"] is not None
assert len(response["spiff__logs"]) > 0

0 comments on commit 270c43c

Please sign in to comment.