|
1 | 1 | import json
|
| 2 | +import logging |
2 | 3 |
|
3 | 4 | import pytest
|
| 5 | +import requests |
4 | 6 | import responses
|
5 | 7 | from requests.exceptions import ConnectionError
|
6 | 8 |
|
@@ -52,6 +54,39 @@ def test_jira_create_issue_is_instrumented(
|
52 | 54 | mocked_statsd.timer.assert_called_with("jbi.jira.methods.create_issue.timer")
|
53 | 55 |
|
54 | 56 |
|
| 57 | +@pytest.mark.no_mocked_jira |
| 58 | +def test_jira_calls_log_http_errors(mocked_responses, context_create_example, caplog): |
| 59 | + url = f"{get_settings().jira_base_url}rest/api/2/project/{context_create_example.jira.project}/components" |
| 60 | + mocked_responses.add( |
| 61 | + responses.GET, |
| 62 | + url, |
| 63 | + status=404, |
| 64 | + json={ |
| 65 | + "errorMessages": ["No project could be found with key 'X'."], |
| 66 | + "errors": {}, |
| 67 | + }, |
| 68 | + ) |
| 69 | + |
| 70 | + with caplog.at_level(logging.ERROR): |
| 71 | + with pytest.raises(requests.HTTPError): |
| 72 | + jira.create_jira_issue( |
| 73 | + context_create_example, |
| 74 | + "Description", |
| 75 | + sync_whiteboard_labels=False, |
| 76 | + components=["Remote Settings"], |
| 77 | + ) |
| 78 | + |
| 79 | + log_messages = [log.msg % log.args for log in caplog.records] |
| 80 | + idx = log_messages.index( |
| 81 | + "HTTP: GET /rest/api/2/project/JBI/components -> 404 Not Found" |
| 82 | + ) |
| 83 | + log_record = caplog.records[idx] |
| 84 | + assert ( |
| 85 | + log_record.body |
| 86 | + == '{"errorMessages": ["No project could be found with key \'X\'."], "errors": {}}' |
| 87 | + ) |
| 88 | + |
| 89 | + |
55 | 90 | @pytest.mark.no_mocked_jira
|
56 | 91 | def test_create_issue_with_components(mocked_responses, context_create_example):
|
57 | 92 | url = f"{get_settings().jira_base_url}rest/api/2/project/{context_create_example.jira.project}/components"
|
|
0 commit comments