def update_exp_id_to_ds_bug_task(user_id, experiment_id): metrics.incr("update_add_experiment_id_to_ds_bug.started") experiment = Experiment.objects.get(id=experiment_id) ds_bug_url = experiment.data_science_bugzilla_url ds_bug_id = bugzilla.get_bugzilla_id(ds_bug_url) request_body = {"blocks": {"add": [experiment.bugzilla_id]}} url = settings.BUGZILLA_UPDATE_URL.format(id=ds_bug_id) try: logger.info("adding block experiment id to ds bug id") bugzilla.make_bugzilla_call(url, requests.put, data=request_body) Notification.objects.create( user_id=user_id, message=NOTIFICATION_MESSAGE_DS_UPDATE.format( bug_url=experiment.data_science_bugzilla_url ), ) metrics.incr("update_exp_id_to_ds_bug.completed") logger.info("Data Science Bug status comment sent") except bugzilla.BugzillaError: metrics.incr("update_exp_id_to_ds_bug.failed") logger.info("Failed to add a status comment to db bugzilla ticket") Notification.objects.create( user_id=user_id, message=NOTIFICATION_MESSAGE_DS_UPDATE_ERROR.format( bug_url=experiment.data_science_bugzilla_url ), )
def test_api_error_logs_message(self): mock_response_data = {"message": "Error: Something went wrong"} mock_response = mock.Mock() mock_response.json = mock.Mock() mock_response.json.return_value = mock_response_data mock_response.status_code = 400 self.mock_bugzilla_requests_put.return_value = mock_response response_data = make_bugzilla_call("/url/", requests.put, data={}) self.assertEqual(response_data, mock_response_data)
def test_api_error_logs_message(self): mock_response_data = {"message": "Error creating Bugzilla Bug because of reasons"} mock_response = mock.Mock() mock_response = mock.Mock() mock_response.json = mock.Mock() mock_response.json.return_value = mock_response_data mock_response.status_code = 400 self.mock_bugzilla_requests_post.return_value = mock_response response_data = make_bugzilla_call("/url/", requests.post, data={}) self.assertEqual(response_data, mock_response_data)
def test_json_parse_error_raises_bugzilla_error(self): self.mock_bugzilla_requests_put.side_effect = ValueError() with self.assertRaises(BugzillaError): make_bugzilla_call("/url/", requests.put, data={})