-
Notifications
You must be signed in to change notification settings - Fork 55
/
test_time_to_ready_for_review.py
59 lines (46 loc) · 2.2 KB
/
test_time_to_ready_for_review.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""A module containing unit tests for the time_to_ready_for_review module.
This module contains unit tests for the get_time_to_ready_for_review
function in the time_to_ready_for_review module.
The tests use mock GitHub issues to test the functions' behavior.
Classes:
TestGetTimeToReadyForReview: A class to test the get_time_to_ready_for_review function.
"""
import unittest
from datetime import datetime
from unittest.mock import MagicMock
from time_to_ready_for_review import get_time_to_ready_for_review
class TestGetTimeToReadyForReview(unittest.TestCase):
"""Test suite for the get_time_to_ready_for_review function."""
# def draft pr function
def test_time_to_ready_for_review_draft(self):
"""Test that the function returns None when the pull request is a draft"""
pull_request = MagicMock()
pull_request.draft = True
issue = MagicMock()
result = get_time_to_ready_for_review(issue, pull_request)
expected_result = None
self.assertEqual(result, expected_result)
def test_get_time_to_ready_for_review_event(self):
"""Test that the function correctly gets the time a pull request was marked as ready for review"""
pull_request = MagicMock()
pull_request.draft = False
event = MagicMock()
event.event = "ready_for_review"
event.created_at = datetime.fromisoformat("2021-01-01T00:00:00Z")
issue = MagicMock()
issue.issue.events.return_value = [event]
result = get_time_to_ready_for_review(issue, pull_request)
expected_result = event.created_at
self.assertEqual(result, expected_result)
def test_get_time_to_ready_for_review_no_event(self):
"""Test that the function returns None when the pull request is not a draft and no ready_for_review event is found"""
pull_request = MagicMock()
pull_request.draft = False
event = MagicMock()
event.event = "foobar"
event.created_at = "2021-01-01T00:00:00Z"
issue = MagicMock()
issue.events.return_value = [event]
result = get_time_to_ready_for_review(issue, pull_request)
expected_result = None
self.assertEqual(result, expected_result)