diff --git a/manager/api/tests/test_jira.py b/manager/api/tests/test_jira.py index 2021ff51..f5e000fc 100644 --- a/manager/api/tests/test_jira.py +++ b/manager/api/tests/test_jira.py @@ -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) @@ -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") @@ -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" diff --git a/manager/manager/utils.py b/manager/manager/utils.py index 2b9b33d9..92ae55f7 100644 --- a/manager/manager/utils.py +++ b/manager/manager/utils.py @@ -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(