1
+ """Integration test for assignee functionality."""
2
+
3
+ import json
4
+ import os
5
+ import tempfile
6
+ import unittest
7
+ from unittest .mock import MagicMock , patch
8
+ from datetime import datetime , timedelta
9
+ from classes import IssueWithMetrics
10
+ from markdown_writer import write_to_markdown
11
+ from json_writer import write_to_json
12
+
13
+
14
+ class TestAssigneeIntegration (unittest .TestCase ):
15
+ """Integration test for assignee functionality."""
16
+
17
+ @patch .dict (
18
+ os .environ ,
19
+ {
20
+ "GH_TOKEN" : "test_token" ,
21
+ "SEARCH_QUERY" : "repo:test/repo is:issue" ,
22
+ },
23
+ clear = True ,
24
+ )
25
+ def test_assignee_in_markdown_output (self ):
26
+ """Test that assignee information appears correctly in markdown output."""
27
+ issues_with_metrics = [
28
+ IssueWithMetrics (
29
+ title = "Test Issue 1" ,
30
+ html_url = "https://github.com/test/repo/issues/1" ,
31
+ author = "john" ,
32
+ assignee = "alice" ,
33
+ assignees = ["alice" ],
34
+ time_to_first_response = timedelta (hours = 2 ),
35
+ time_to_close = timedelta (days = 1 ),
36
+ created_at = datetime .now () - timedelta (days = 2 ),
37
+ ),
38
+ IssueWithMetrics (
39
+ title = "Test Issue 2" ,
40
+ html_url = "https://github.com/test/repo/issues/2" ,
41
+ author = "jane" ,
42
+ assignee = None ,
43
+ assignees = [],
44
+ time_to_first_response = timedelta (hours = 4 ),
45
+ time_to_close = None ,
46
+ created_at = datetime .now () - timedelta (days = 1 ),
47
+ ),
48
+ ]
49
+
50
+ with tempfile .NamedTemporaryFile (mode = 'w' , suffix = '.md' , delete = False ) as f :
51
+ output_file = f .name
52
+
53
+ try :
54
+ write_to_markdown (
55
+ issues_with_metrics = issues_with_metrics ,
56
+ average_time_to_first_response = {"avg" : timedelta (hours = 3 ), "med" : timedelta (hours = 3 ), "90p" : timedelta (hours = 4 )},
57
+ average_time_to_close = {"avg" : timedelta (days = 1 ), "med" : timedelta (days = 1 ), "90p" : timedelta (days = 1 )},
58
+ average_time_to_answer = None ,
59
+ average_time_in_draft = None ,
60
+ average_time_in_labels = None ,
61
+ num_issues_opened = 2 ,
62
+ num_issues_closed = 1 ,
63
+ num_mentor_count = 0 ,
64
+ labels = None ,
65
+ search_query = "repo:test/repo is:issue" ,
66
+ hide_label_metrics = True ,
67
+ hide_items_closed_count = False ,
68
+ enable_mentor_count = False ,
69
+ non_mentioning_links = False ,
70
+ report_title = "Test Issue Metrics" ,
71
+ output_file = output_file ,
72
+ ghe = "" ,
73
+ )
74
+
75
+ # Read and verify the markdown content
76
+ with open (output_file , 'r' ) as f :
77
+ content = f .read ()
78
+
79
+ # Check for assignee column header
80
+ self .assertIn ("| Assignee |" , content )
81
+
82
+ # Check for assignee data - alice should be linked
83
+ self .assertIn ("[alice](https://github.com/alice)" , content )
84
+
85
+ # Check for None assignee
86
+ self .assertIn ("| None |" , content )
87
+
88
+ # Check that both assignee and author columns are present
89
+ self .assertIn ("| Author |" , content )
90
+
91
+ finally :
92
+ os .unlink (output_file )
93
+
94
+ def test_assignee_in_json_output (self ):
95
+ """Test that assignee information appears correctly in JSON output."""
96
+ issues_with_metrics = [
97
+ IssueWithMetrics (
98
+ title = "Test Issue 1" ,
99
+ html_url = "https://github.com/test/repo/issues/1" ,
100
+ author = "john" ,
101
+ assignee = "alice" ,
102
+ assignees = ["alice" , "bob" ],
103
+ time_to_first_response = timedelta (hours = 2 ),
104
+ time_to_close = timedelta (days = 1 ),
105
+ created_at = datetime .now () - timedelta (days = 2 ),
106
+ ),
107
+ IssueWithMetrics (
108
+ title = "Test Issue 2" ,
109
+ html_url = "https://github.com/test/repo/issues/2" ,
110
+ author = "jane" ,
111
+ assignee = None ,
112
+ assignees = [],
113
+ time_to_first_response = timedelta (hours = 4 ),
114
+ time_to_close = None ,
115
+ created_at = datetime .now () - timedelta (days = 1 ),
116
+ ),
117
+ ]
118
+
119
+ with tempfile .NamedTemporaryFile (mode = 'w' , suffix = '.json' , delete = False ) as f :
120
+ output_file = f .name
121
+
122
+ try :
123
+ json_output = write_to_json (
124
+ issues_with_metrics = issues_with_metrics ,
125
+ stats_time_to_first_response = {"avg" : timedelta (hours = 3 ), "med" : timedelta (hours = 3 ), "90p" : timedelta (hours = 4 )},
126
+ stats_time_to_close = {"avg" : timedelta (days = 1 ), "med" : timedelta (days = 1 ), "90p" : timedelta (days = 1 )},
127
+ stats_time_to_answer = None ,
128
+ stats_time_in_draft = None ,
129
+ stats_time_in_labels = None ,
130
+ num_issues_opened = 2 ,
131
+ num_issues_closed = 1 ,
132
+ num_mentor_count = 0 ,
133
+ search_query = "repo:test/repo is:issue" ,
134
+ output_file = output_file ,
135
+ )
136
+
137
+ # Parse the JSON output
138
+ data = json .loads (json_output )
139
+
140
+ # Check that assignee fields are present
141
+ issue1 = data ["issues" ][0 ]
142
+ self .assertEqual (issue1 ["assignee" ], "alice" )
143
+ self .assertEqual (issue1 ["assignees" ], ["alice" , "bob" ])
144
+ self .assertEqual (issue1 ["author" ], "john" )
145
+
146
+ issue2 = data ["issues" ][1 ]
147
+ self .assertIsNone (issue2 ["assignee" ])
148
+ self .assertEqual (issue2 ["assignees" ], [])
149
+ self .assertEqual (issue2 ["author" ], "jane" )
150
+
151
+ finally :
152
+ os .unlink (output_file )
153
+
154
+
155
+ if __name__ == "__main__" :
156
+ unittest .main ()
0 commit comments