|
30 | 30 |
|
31 | 31 | from manager.utils import (
|
32 | 32 | TIME_LOST_FIELD,
|
| 33 | + get_jira_obs_report, |
33 | 34 | handle_jira_payload,
|
34 | 35 | jira_comment,
|
35 | 36 | jira_ticket,
|
@@ -488,3 +489,61 @@ def test_handle_exposure_jira_payload(self):
|
488 | 489 | )
|
489 | 490 |
|
490 | 491 | mock_jira_patcher.stop()
|
| 492 | + |
| 493 | + def test_get_jira_obs_report(self): |
| 494 | + """Test call to get_jira_obs_report |
| 495 | + function with all needed parameters""" |
| 496 | + mock_jira_patcher = patch("requests.get") |
| 497 | + mock_jira_client = mock_jira_patcher.start() |
| 498 | + response = requests.Response() |
| 499 | + response.status_code = 200 |
| 500 | + response.json = lambda: { |
| 501 | + "issues": [ |
| 502 | + { |
| 503 | + "key": "LOVE-XX", |
| 504 | + "fields": { |
| 505 | + "summary": "Issue title", |
| 506 | + TIME_LOST_FIELD: 13.6, |
| 507 | + "creator": {"displayName": "user"}, |
| 508 | + "created": "2022-07-03T19:58:13.00000", |
| 509 | + }, |
| 510 | + } |
| 511 | + ] |
| 512 | + } |
| 513 | + mock_jira_client.return_value = response |
| 514 | + |
| 515 | + request_data = { |
| 516 | + "day_obs": 20240902, |
| 517 | + } |
| 518 | + jira_response = get_jira_obs_report(request_data) |
| 519 | + assert jira_response[0]["key"] == "LOVE-XX" |
| 520 | + assert jira_response[0]["summary"] == "Issue title" |
| 521 | + assert jira_response[0]["time_lost"] == 13.6 |
| 522 | + assert jira_response[0]["reporter"] == "user" |
| 523 | + assert jira_response[0]["created"] == "2022-07-03T19:58:13" |
| 524 | + |
| 525 | + mock_jira_patcher.stop() |
| 526 | + |
| 527 | + def test_get_jira_obs_report_fail(self): |
| 528 | + """Test call to get_jira_obs_report function with fail response""" |
| 529 | + mock_jira_patcher = patch("requests.get") |
| 530 | + mock_jira_client = mock_jira_patcher.start() |
| 531 | + response = requests.Response() |
| 532 | + response.status_code = 400 |
| 533 | + mock_jira_client.return_value = response |
| 534 | + |
| 535 | + request_data = { |
| 536 | + "day_obs": 20240902, |
| 537 | + } |
| 538 | + with pytest.raises(Exception): |
| 539 | + get_jira_obs_report(request_data) |
| 540 | + |
| 541 | + mock_jira_patcher.stop() |
| 542 | + |
| 543 | + def test_get_jira_obs_report_bad_date(self): |
| 544 | + """Test call to get_jira_obs_report function with bad date""" |
| 545 | + request_data = { |
| 546 | + "day_obs": 20240931, |
| 547 | + } |
| 548 | + with pytest.raises(ValueError): |
| 549 | + get_jira_obs_report(request_data) |
0 commit comments