-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathtest_assignee_functionality.py
More file actions
225 lines (199 loc) · 7.43 KB
/
test_assignee_functionality.py
File metadata and controls
225 lines (199 loc) · 7.43 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
"""Test assignee functionality added to issue metrics."""
import os
import unittest
from unittest.mock import patch
from classes import IssueWithMetrics
from markdown_writer import get_non_hidden_columns
class TestAssigneeFunctionality(unittest.TestCase):
"""Test suite for the assignee functionality."""
@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_ASSIGNEE": "false",
"HIDE_AUTHOR": "false",
},
clear=True,
)
def test_get_non_hidden_columns_includes_assignee_by_default(self):
"""Test that assignee column is included by default."""
columns = get_non_hidden_columns(labels=None)
self.assertIn("Assignee", columns)
self.assertIn("Author", columns)
@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_ASSIGNEE": "true",
"HIDE_AUTHOR": "false",
},
clear=True,
)
def test_get_non_hidden_columns_hides_assignee_when_env_set(self):
"""Test that assignee column is hidden when HIDE_ASSIGNEE is true."""
columns = get_non_hidden_columns(labels=None)
self.assertNotIn("Assignee", columns)
self.assertIn("Author", columns)
@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_ASSIGNEE": "false",
"HIDE_AUTHOR": "true",
},
clear=True,
)
def test_get_non_hidden_columns_shows_assignee_but_hides_author(self):
"""Test that assignee can be shown while author is hidden."""
columns = get_non_hidden_columns(labels=None)
self.assertIn("Assignee", columns)
self.assertNotIn("Author", columns)
@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_ASSIGNEE": "true",
"HIDE_AUTHOR": "true",
},
clear=True,
)
def test_get_non_hidden_columns_hides_both_assignee_and_author(self):
"""Test that both assignee and author can be hidden."""
columns = get_non_hidden_columns(labels=None)
self.assertNotIn("Assignee", columns)
self.assertNotIn("Author", columns)
@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_STATUS": "false",
},
clear=True,
)
def test_get_non_hidden_columns_includes_status_by_default(self):
"""Test that status column is included by default."""
columns = get_non_hidden_columns(labels=None)
self.assertIn("Status", columns)
@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_STATUS": "true",
},
clear=True,
)
def test_get_non_hidden_columns_hides_status_when_env_set(self):
"""Test that status column is hidden when HIDE_STATUS is true."""
columns = get_non_hidden_columns(labels=None)
self.assertNotIn("Status", columns)
def test_assignee_column_position(self):
"""Test that assignee column appears before author column."""
with patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_ASSIGNEE": "false",
"HIDE_AUTHOR": "false",
},
clear=True,
):
columns = get_non_hidden_columns(labels=None)
assignee_index = columns.index("Assignee")
author_index = columns.index("Author")
self.assertLess(
assignee_index,
author_index,
"Assignee column should appear before Author column",
)
def test_multiple_assignees_rendering_logic(self):
"""Test that multiple assignees are rendered correctly in assignee column."""
# Test the assignee rendering logic directly
endpoint = "github.com"
columns = ["Title", "URL", "Assignee", "Author"]
# Initialize variables
multiple_output = ""
single_output = ""
none_output = ""
# Test case 1: Multiple assignees
issue_multiple = IssueWithMetrics(
title="Test Issue with Multiple Assignees",
html_url="https://github.com/test/repo/issues/1",
author="testuser",
assignee="alice",
assignees=["alice", "bob", "charlie"],
)
# Simulate the new rendering logic
if "Assignee" in columns:
if issue_multiple.assignees:
assignee_links = [
f"[{assignee}](https://{endpoint}/{assignee})"
for assignee in issue_multiple.assignees
]
multiple_output = f" {', '.join(assignee_links)} |"
else:
multiple_output = " None |"
expected_multiple = (
" [alice](https://github.com/alice), [bob](https://github.com/bob), "
"[charlie](https://github.com/charlie) |"
)
self.assertEqual(
multiple_output,
expected_multiple,
"Multiple assignees should be rendered as comma-separated links",
)
# Test case 2: Single assignee
issue_single = IssueWithMetrics(
title="Test Issue with Single Assignee",
html_url="https://github.com/test/repo/issues/2",
author="testuser",
assignee="alice",
assignees=["alice"],
)
if "Assignee" in columns:
if issue_single.assignees:
assignee_links = [
f"[{assignee}](https://{endpoint}/{assignee})"
for assignee in issue_single.assignees
]
single_output = f" {', '.join(assignee_links)} |"
else:
single_output = " None |"
expected_single = " [alice](https://github.com/alice) |"
self.assertEqual(
single_output,
expected_single,
"Single assignee should be rendered as a single link",
)
# Test case 3: No assignees
issue_none = IssueWithMetrics(
title="Test Issue with No Assignees",
html_url="https://github.com/test/repo/issues/3",
author="testuser",
assignee=None,
assignees=[],
)
if "Assignee" in columns:
if issue_none.assignees:
assignee_links = [
f"[{assignee}](https://{endpoint}/{assignee})"
for assignee in issue_none.assignees
]
none_output = f" {', '.join(assignee_links)} |"
else:
none_output = " None |"
expected_none = " None |"
self.assertEqual(
none_output, expected_none, "No assignees should be rendered as 'None'"
)
print(f"✅ Multiple assignees test: {expected_multiple}")
print(f"✅ Single assignee test: {expected_single}")
print(f"✅ No assignees test: {expected_none}")
if __name__ == "__main__":
unittest.main()