-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathtest_githublabeler.py
84 lines (75 loc) · 4.3 KB
/
test_githublabeler.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
import githublabeler
import pytest
from datetime import datetime, timezone
FAKE_ID = 'fakeID'
activeDiscussionPosts = [{'id': FAKE_ID, # active because of lastEditedAt only
'createdAt': '2022-06-01T22:42:26Z',
'lastEditedAt': '2023-06-01T22:42:26Z',
'comments': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2022-06-01T22:42:26Z',
'replies': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2022-06-01T22:42:26Z'}]}}]}},
{'id': FAKE_ID, # active because of comments only
'createdAt': '2022-06-01T22:42:26Z',
'lastEditedAt': '2022-06-01T22:42:26Z',
'comments': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2023-06-01T22:42:26Z',
'replies': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2022-06-01T22:42:26Z'}]}}]}},
{'id': FAKE_ID, # active because of comment reply only
'createdAt': '2022-06-01T22:42:26Z',
'lastEditedAt': '2022-06-01T22:42:26Z',
'comments': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2022-06-01T22:42:26Z',
'replies': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2023-06-01T22:42:26Z'}]}}]}}]
quietDiscussionPosts = [{'id': FAKE_ID,
'createdAt': '2022-06-01T22:42:26Z',
'lastEditedAt': '2022-06-01T22:42:26Z',
'comments': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2022-06-01T22:42:26Z',
'replies': {'nodes': [{'createdAt': '2022-06-01T22:42:26Z',
'updatedAt': '2022-06-01T22:42:26Z'}]}}]}}]
newDiscussionPosts = [{'id': FAKE_ID,
'createdAt': '2023-06-01T22:42:26Z',
'lastEditedAt': '2023-06-01T22:42:26Z',
'comments': {'nodes': [{'createdAt': '2023-06-01T22:42:26Z',
'updatedAt': '2023-06-01T22:42:26Z',
'replies': {'nodes': [{'createdAt': '2023-06-01T22:42:26Z',
'updatedAt': '2023-06-01T22:42:26Z'}]}}]}}]
def test_isActive():
now = datetime.fromisoformat("2023-06-14T17:39:37Z")
for d in activeDiscussionPosts:
assert githublabeler.isActive(d, now)
for d in quietDiscussionPosts:
assert githublabeler.isActive(d, now) == False
def test_getUpdates():
now = datetime.fromisoformat("2023-06-14T17:39:37Z")
assert githublabeler.getUpdates(quietDiscussionPosts, now) == [{
'id': FAKE_ID,
'add': [
githublabeler.QUIET_LABEL], 'remove': [
githublabeler.NEW_LABEL, githublabeler.ACTIVE_LABEL]
}]
assert githublabeler.getUpdates(activeDiscussionPosts, now) == [{
'id': FAKE_ID,
'add': [
githublabeler.ACTIVE_LABEL], 'remove': [
githublabeler.NEW_LABEL, githublabeler.QUIET_LABEL]
}, {
'id': FAKE_ID,
'add': [
githublabeler.ACTIVE_LABEL], 'remove': [
githublabeler.NEW_LABEL, githublabeler.QUIET_LABEL]
}, {
'id': FAKE_ID,
'add': [
githublabeler.ACTIVE_LABEL], 'remove': [
githublabeler.NEW_LABEL, githublabeler.QUIET_LABEL]
}]
assert githublabeler.getUpdates(newDiscussionPosts, now) == [{
'id': FAKE_ID,
'add': [
githublabeler.NEW_LABEL, githublabeler.ACTIVE_LABEL], 'remove': [
githublabeler.QUIET_LABEL]
}]