Skip to content

Commit

Permalink
Added test to fail jira comment, Django Response is not the same as r…
Browse files Browse the repository at this point in the history
…equests Response
  • Loading branch information
Vebop committed Aug 22, 2024
1 parent ee9bd84 commit 4951cf8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 22 additions & 0 deletions manager/api/tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,22 @@ def test_add_comment(self):
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira comment created"

def test_add_comment_fail(self):
mock_jira_patcher = patch("requests.post")
mock_jira_client = mock_jira_patcher.start()
response = requests.Response()
response.status_code = 201
mock_jira_client.return_value = response

mock_time_lost_patcher = patch("manager.utils.update_time_lost")
mock_time_lost_client = mock_time_lost_patcher.start()
time_response = requests.Response()
time_response.status_code = 400
mock_time_lost_client.return_value = time_response

resp = jira_comment(self.jira_request_narrative_full_jira_comment.data)
assert resp.status_code == 400

@patch.dict(os.environ, {"JIRA_API_HOSTNAME": "jira.lsstcorp.org"})
def test_handle_narrative_jira_payload(self):
"""Test call to function handle_jira_payload with all needed parameters
Expand All @@ -378,6 +394,12 @@ def test_handle_narrative_jira_payload(self):
response.json = lambda: {"key": "LOVE-XX"}
mock_jira_client.return_value = response

mock_time_lost_patcher = patch("manager.utils.update_time_lost")
mock_time_lost_client = mock_time_lost_patcher.start()
time_response = requests.Response()
time_response.status_code = 200
mock_time_lost_client.return_value = time_response

jira_response = handle_jira_payload(self.jira_request_narrative_full_jira_new)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira ticket created"
Expand Down
1 change: 0 additions & 1 deletion manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,6 @@ def jira_comment(request_data):
}
url = f"https://{os.environ.get('JIRA_API_HOSTNAME')}/rest/api/latest/issue/{jira_id}/comment"
response = requests.post(url, json=jira_payload, headers=headers)

if "time_lost" in request_data:
timelost_response = update_time_lost(
jira_id=jira_id, add_time_lost=request_data.get("time_lost", 0.0)
Expand Down

0 comments on commit 4951cf8

Please sign in to comment.