Skip to content

Commit

Permalink
handling more comments from pr
Browse files Browse the repository at this point in the history
  • Loading branch information
Vebop committed Aug 22, 2024
1 parent 907b1c8 commit ee9bd84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
27 changes: 17 additions & 10 deletions manager/api/tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,19 @@ def test_needed_parameters(self):

mock_jira_patcher.stop()

@patch("requests.get")
@patch("requests.put")
def test_update_time_lost(self, mock_get, mock_put):
def test_update_time_lost(self):
"""Test call to update_time_lost and verify field was updated"""
# patch both requests.get, requests.put
mock_jira_patcher = patch("requests.get")
mock_jira_get = mock_jira_patcher.start()
response = requests.Response()
response.status_code = 200
response.json = lambda: {TIME_LOST_FIELD: 13.6}
mock_get.return_value = response
mock_jira_get.return_value = response

put_patcher = patch("requests.put")
mock_jira_put = put_patcher.start()
response.status_code = 204
mock_put.return_value = response
mock_jira_put.return_value = response

# call update time lost
jira_response = update_time_lost(1, 3.4)
Expand All @@ -339,6 +340,12 @@ def test_update_time_lost(self, mock_get, mock_put):
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira time_lost field updated"

response.status_code = 400
mock_jira_put.return_value = response

jira_response = update_time_lost(12, 97.01)
assert jira_response.status_code == 400

def test_add_comment(self):
"""Test call to jira_comment function with all needed parameters"""
mock_jira_patcher = patch("requests.post")
Expand All @@ -347,14 +354,14 @@ def test_add_comment(self):
response.status_code = 201
mock_jira_client.return_value = response

mock_timeloss_patcher = patch("manager.utils.update_time_lost")
mock_timeloss_client = mock_timeloss_patcher.start()
mock_timeloss_client.return_value = response

jira_response = jira_comment(self.jira_request_exposure_full_jira_comment.data)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira comment created"

mock_time_lost_patcher = patch("manager.utils.update_time_lost")
mock_time_lost_client = mock_time_lost_patcher.start()
mock_time_lost_client.return_value = response

jira_response = jira_comment(self.jira_request_narrative_full_jira_comment.data)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira comment created"
Expand Down
6 changes: 3 additions & 3 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,11 @@ def jira_comment(request_data):
response = requests.post(url, json=jira_payload, headers=headers)

if "time_lost" in request_data:
response = update_time_lost(
timelost_response = update_time_lost(
jira_id=jira_id, add_time_lost=request_data.get("time_lost", 0.0)
)
if response.status_code == 400:
return response
if timelost_response.status_code == 400:
return timelost_response

if response.status_code == 201:
return Response(
Expand Down

0 comments on commit ee9bd84

Please sign in to comment.