fixed tests w/ burnettk

This commit is contained in:
jasquat 2024-06-12 11:53:08 -04:00
parent 9d03aa6630
commit 270c43ca4e
No known key found for this signature in database
3 changed files with 38 additions and 2 deletions

View File

@ -21,7 +21,7 @@ jobs:
strategy: strategy:
fail-fast: true fail-fast: true
matrix: matrix:
python-version: [ "3.10", "3.11" ] python-version: ["3.10", "3.11"]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out repository - name: Check out repository

View File

@ -81,7 +81,11 @@ class HttpRequestBase:
if self.params is not None: if self.params is not None:
arguments["params"] = self.params arguments["params"] = self.params
if self.data is not None: 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["headers"]["Content-Type"] = "application/json"
arguments["json"] = self.data arguments["json"] = self.data
http_response = request_function(**arguments) http_response = request_function(**arguments)

View File

@ -6,6 +6,14 @@ from connector_http.commands.put_request_v2 import PutRequestV2
class TestPutRequestV2: 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: def test_put_html_from_url(self) -> None:
request = PutRequestV2(url="http://example.com") request = PutRequestV2(url="http://example.com")
return_html = "<html>Hey</html>" return_html = "<html>Hey</html>"
@ -15,6 +23,7 @@ class TestPutRequestV2:
mock_request.return_value.text = return_html mock_request.return_value.text = return_html
response = request.execute(None, {}) response = request.execute(None, {})
assert mock_request.call_count == 1 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"]["body"] == {"raw_response": return_html}
assert response["command_response"]["http_status"] == 200 assert response["command_response"]["http_status"] == 200
@ -33,6 +42,7 @@ class TestPutRequestV2:
mock_request.return_value.text = json.dumps(return_json) mock_request.return_value.text = json.dumps(return_json)
response = request.execute(None, {}) response = request.execute(None, {})
assert mock_request.call_count == 1 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 is not None
assert response["command_response"]["body"] == return_json assert response["command_response"]["body"] == return_json
@ -51,6 +61,7 @@ class TestPutRequestV2:
mock_request.return_value.text = json.dumps(return_json) mock_request.return_value.text = json.dumps(return_json)
response = request.execute(None, {}) response = request.execute(None, {})
assert mock_request.call_count == 1 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 is not None
assert response["command_response"]["body"] == return_json assert response["command_response"]["body"] == return_json
@ -59,3 +70,24 @@ class TestPutRequestV2:
assert response["error"] is not None assert response["error"] is not None
assert response["spiff__logs"] is not None assert response["spiff__logs"] is not None
assert len(response["spiff__logs"]) > 0 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