-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
306 lines (291 loc) · 13.5 KB
/
test.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import action
# import json
import os
import unittest
TEST_TOKEN = "TEST_TOKEN"
TEST_EVENT_PATH = "/tmp/event-path.json"
TEST_REPO_NAME = "fake/repo"
class TestEventoData(unittest.TestCase):
def setUp(self):
os.environ["GITHUB_TOKEN"] = TEST_TOKEN
os.environ["GITHUB_EVENT_PATH"] = TEST_EVENT_PATH
os.environ["GITHUB_REPOSITORY"] = TEST_REPO_NAME
# create a fake event file
self.issue = {
"id": 1,
"node_id": "MDU6SXNzdWUx",
"url": "https://api.github.com/repos/octocat/Hello-World/issues/\
1347",
"repository_url": "https://api.github.com/repos/octocat/\
Hello-World",
"labels_url": "https://api.github.com/repos/octocat/Hello-World/\
issues/1347/labels{/name}",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/\
issues/1347/comments",
"events_url": "https://api.github.com/repos/octocat/Hello-World/\
issues/1347/events",
"html_url": "https://github.com/octocat/Hello-World/issues/1347",
"number": 1347,
"state": "open",
"title": "Found a bug",
"body": """Descrição: Evento muito maneiro de python!
Data sugerida: 26/10/2019
Nome: Fulaninho
Email: [email protected]""",
"user": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/\
octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/\
followers",
"following_url": "https://api.github.com/users/octocat/\
following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/\
gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/\
starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/\
subscriptions",
"organizations_url": "https://api.github.com/users/octocat/\
orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/\
events{/privacy}",
"received_events_url": "https://api.github.com/users/\
octocat/received_events",
"type": "User",
"site_admin": False,
},
"labels": [
{
"id": 208045946,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
"url": "https://api.github.com/repos/octocat/Hello-World/\
labels/bug",
"name": "evento",
"description": "Something isn't working",
"color": "f29513",
"default": True,
}
],
"assignee": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/\
octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/\
followers",
"following_url": "https://api.github.com/users/octocat/\
following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/\
gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/\
starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/\
octocat/subscriptions",
"organizations_url": "https://api.github.com/users/\
octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/\
events{/privacy}",
"received_events_url": "https://api.github.com/users/\
octocat/received_events",
"type": "User",
"site_admin": False,
},
"assignees": [
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/\
octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/\
octocat/followers",
"following_url": "https://api.github.com/users/\
octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/\
gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/\
starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/\
octocat/subscriptions",
"organizations_url": "https://api.github.com/users/\
octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/\
repos",
"events_url": "https://api.github.com/users/octocat/\
events{/privacy}",
"received_events_url": "https://api.github.com/users/\
octocat/received_events",
"type": "User",
"site_admin": False,
}
],
"milestone": {
"url": "https://api.github.com/repos/octocat/Hello-World/\
milestones/1",
"html_url": "https://github.com/octocat/Hello-World/\
milestones/v1.0",
"labels_url": "https://api.github.com/repos/octocat/\
Hello-World/milestones/1/labels",
"id": 1002604,
"node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==",
"number": 1,
"state": "open",
"title": "v1.0",
"description": "Tracking milestone for version 1.0",
"creator": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/\
octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/\
octocat/followers",
"following_url": "https://api.github.com/users/\
octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/\
gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/\
starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/\
octocat/subscriptions",
"organizations_url": "https://api.github.com/users/\
octocat/orgs",
"repos_url": "https://api.github.com/users/\
octocat/repos",
"events_url": "https://api.github.com/users/octocat/\
events{/privacy}",
"received_events_url": "https://api.github.com/users/\
octocat/received_events",
"type": "User",
"site_admin": False,
},
"open_issues": 4,
"closed_issues": 8,
"created_at": "2011-04-10T20:09:31Z",
"updated_at": "2014-03-03T18:58:10Z",
"closed_at": "2013-02-12T13:22:01Z",
"due_on": "2012-10-09T23:39:01Z",
},
"locked": True,
"active_lock_reason": "too heated",
"comments": 0,
"pull_request": {
"url": "https://api.github.com/repos/octocat/Hello-World/\
pulls/1347",
"html_url": "https://github.com/octocat/Hello-World/pull/1347",
"diff_url": "https://github.com/octocat/Hello-World/pull/\
1347.diff",
"patch_url": "https://github.com/octocat/Hello-World/pull/\
1347.patch",
},
"closed_at": None,
"created_at": "2011-04-22T13:33:48Z",
"updated_at": "2011-04-22T13:33:48Z",
"closed_by": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/\
octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/\
followers",
"following_url": "https://api.github.com/users/octocat/\
following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/\
gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/\
starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/\
subscriptions",
"organizations_url": "https://api.github.com/users/octocat/\
orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/\
events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/\
e received_events",
"type": "User",
"site_admin": False,
},
}
self.event = {"issue": self.issue}
def test_get_token(self):
self.assertEqual(action.get_access_token(), TEST_TOKEN)
def test_get_event_file(self):
self.assertEqual(action.get_event_file(), TEST_EVENT_PATH)
def test_is_first_section_line(self):
self.assertTrue(
action.is_first_section_line(
"Descrição: Evento \
muito maneiro de python!"
)
)
self.assertTrue(action.is_first_section_line("Nome: Python Brasil"))
self.assertTrue(
action.is_first_section_line(
"Data sugerida: \
26/10/2019"
)
)
self.assertTrue(
action.is_first_section_line(
"Email: \
)
)
self.assertFalse(
action.is_first_section_line(
"email: \
)
)
self.assertFalse(
action.is_first_section_line(
"Descricao: Evento \
muito maneiro de python!"
)
)
self.assertFalse(action.is_first_section_line("Name: Python Brasil"))
self.assertFalse(action.is_first_section_line("Data: 26/10/2019"))
def test_has_event_label(self):
self.assertTrue(action.has_event_label(self.event))
def test_has_all_required_data(self):
self.assertEqual(0, len(action.validate_data(self.event)))
def test_get_sections(self):
sections = action.get_sections(self.issue["body"])
self.assertEqual(len(sections), 4)
self.assertIn("Descrição", sections, msg="Missing 'descrição'")
self.assertEqual(sections["Descrição"], "Evento muito maneiro de python!")
self.assertIn("Nome", sections, msg="Missing 'Nome'")
self.assertEqual(sections["Nome"], "Fulaninho")
self.assertIn("Email", sections, msg="Missing 'Email'")
self.assertEqual(sections["Email"], "[email protected]")
self.assertIn("Data sugerida", sections, msg="Missing 'Data sugerida'")
self.assertEqual(sections["Data sugerida"], "26/10/2019")
def tet_get_repository_name(self):
self.assertEqual(action.get_repository_name(), TEST_REPO_NAME)
def test_get_issue_number(self):
self.assertEqual(action.get_issue_number(self.event), 1347)
if __name__ == "__main__":
unittest.main()