-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathtest_assignee_integration.py
More file actions
175 lines (153 loc) · 6.05 KB
/
test_assignee_integration.py
File metadata and controls
175 lines (153 loc) · 6.05 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
"""Integration test for assignee functionality."""
import json
import os
import tempfile
import unittest
from datetime import datetime, timedelta
from unittest.mock import patch
from classes import IssueWithMetrics
from json_writer import write_to_json
from markdown_writer import write_to_markdown
class TestAssigneeIntegration(unittest.TestCase):
"""Integration test for assignee functionality."""
@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "repo:test/repo is:issue",
},
clear=True,
)
def test_assignee_in_markdown_output(self):
"""Test that assignee information appears correctly in markdown output."""
issues_with_metrics = [
IssueWithMetrics(
title="Test Issue 1",
html_url="https://github.com/test/repo/issues/1",
author="john",
assignee="alice",
assignees=["alice"],
time_to_first_response=timedelta(hours=2),
time_to_close=timedelta(days=1),
created_at=datetime.now() - timedelta(days=2),
),
IssueWithMetrics(
title="Test Issue 2",
html_url="https://github.com/test/repo/issues/2",
author="jane",
assignee=None,
assignees=[],
time_to_first_response=timedelta(hours=4),
time_to_close=None,
created_at=datetime.now() - timedelta(days=1),
),
]
with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f:
output_file = f.name
try:
write_to_markdown(
issues_with_metrics=issues_with_metrics,
average_time_to_first_response={
"avg": timedelta(hours=3),
"med": timedelta(hours=3),
"90p": timedelta(hours=4),
},
average_time_to_close={
"avg": timedelta(days=1),
"med": timedelta(days=1),
"90p": timedelta(days=1),
},
average_time_to_answer=None,
average_time_in_draft=None,
average_time_in_labels=None,
stats_pr_comments=None,
num_issues_opened=2,
num_issues_closed=1,
num_mentor_count=0,
labels=None,
search_query="repo:test/repo is:issue",
hide_label_metrics=True,
hide_items_closed_count=False,
enable_mentor_count=False,
non_mentioning_links=False,
report_title="Test Issue Metrics",
output_file=output_file,
ghe="",
)
# Read and verify the markdown content
with open(output_file, "r", encoding="utf-8") as f:
content = f.read()
# Check for assignee column header
self.assertIn("| Assignee |", content)
# Check for assignee data - alice should be linked
self.assertIn("[alice](https://github.com/alice)", content)
# Check for None assignee
self.assertIn("| None |", content)
# Check that both assignee and author columns are present
self.assertIn("| Author |", content)
finally:
os.unlink(output_file)
def test_assignee_in_json_output(self):
"""Test that assignee information appears correctly in JSON output."""
issues_with_metrics = [
IssueWithMetrics(
title="Test Issue 1",
html_url="https://github.com/test/repo/issues/1",
author="john",
assignee="alice",
assignees=["alice", "bob"],
time_to_first_response=timedelta(hours=2),
time_to_close=timedelta(days=1),
created_at=datetime.now() - timedelta(days=2),
),
IssueWithMetrics(
title="Test Issue 2",
html_url="https://github.com/test/repo/issues/2",
author="jane",
assignee=None,
assignees=[],
time_to_first_response=timedelta(hours=4),
time_to_close=None,
created_at=datetime.now() - timedelta(days=1),
),
]
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
output_file = f.name
try:
json_output = write_to_json(
issues_with_metrics=issues_with_metrics,
stats_time_to_first_response={
"avg": timedelta(hours=3),
"med": timedelta(hours=3),
"90p": timedelta(hours=4),
},
stats_time_to_close={
"avg": timedelta(days=1),
"med": timedelta(days=1),
"90p": timedelta(days=1),
},
stats_time_to_answer=None,
stats_time_in_draft=None,
stats_time_in_labels=None,
stats_pr_comments=None,
num_issues_opened=2,
num_issues_closed=1,
num_mentor_count=0,
search_query="repo:test/repo is:issue",
output_file=output_file,
)
# Parse the JSON output
data = json.loads(json_output)
# Check that assignee fields are present
issue1 = data["issues"][0]
self.assertEqual(issue1["assignee"], "alice")
self.assertEqual(issue1["assignees"], ["alice", "bob"])
self.assertEqual(issue1["author"], "john")
issue2 = data["issues"][1]
self.assertIsNone(issue2["assignee"])
self.assertEqual(issue2["assignees"], [])
self.assertEqual(issue2["author"], "jane")
finally:
os.unlink(output_file)
if __name__ == "__main__":
unittest.main()