forked from cfpb/github-wiki-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
103 lines (75 loc) · 4.25 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
import unittest
import sync
import types
class TestGitEvents(unittest.TestCase):
def test_get_changed_page_urls_when_one_new_wiki_event_expect_one_url(self):
page_url = 'http://host.com/user/repo/wiki/page'
cut = sync.GitEvents()
def moc_get_page_of_events(self, page=1, etag=True):
return [{'id': '5', 'type': 'gollumEvent', 'pages': [{'html_url': page_url}]}]
cut.get_page_of_events = types.MethodType(moc_get_page_of_events, cut)
actual = cut.get_changed_page_urls()
self.assertEqual(actual, [page_url])
def test_get_changed_page_urls_when_one_new_wiki_event_with_two_changed_pages_expect_two_urls(self):
page1_url = 'http://host.com/user/repo/wiki/page1'
page2_url = 'http://host.com/user/repo/wiki/page2'
cut = sync.GitEvents()
def moc_get_page_of_events(self, page=1, etag=True):
return [{'id': '5', 'type': 'gollumEvent', 'pages': [{'html_url': page1_url}, {'html_url': page2_url}]}]
cut.get_page_of_events = types.MethodType(moc_get_page_of_events, cut)
actual = cut.get_changed_page_urls()
self.assertIn(page1_url, actual)
self.assertIn(page2_url, actual)
self.assertEqual(len(actual), 2)
def test_get_changed_page_urls_when_two_new_wiki_event_for_same_page_expect_one_url(self):
page_url = 'http://host.com/user/repo/wiki/page'
cut = sync.GitEvents()
def moc_get_page_of_events(self, page=1, etag=True):
return [{'id': '6', 'type': 'gollumEvent', 'pages': [{'html_url': page_url}]}, {'id': '5', 'type': 'gollumEvent', 'pages': [{'html_url': page_url}]}]
cut.get_page_of_events = types.MethodType(moc_get_page_of_events, cut)
actual = cut.get_changed_page_urls()
self.assertEqual(actual, [page_url])
def test_get_changed_page_urls_when_one_new_wiki_event_one_other_event_expect_one_url(self):
page_url = 'http://host.com/user/repo/wiki/page'
cut = sync.GitEvents()
def moc_get_page_of_events(self, page=1, etag=True):
return [{'id': '6', 'type': 'add'}, {'id': '5', 'type': 'gollumEvent', 'pages': [{'html_url': page_url}]}]
cut.get_page_of_events = types.MethodType(moc_get_page_of_events, cut)
actual = cut.get_changed_page_urls()
self.assertEqual(actual, [page_url])
def test_get_changed_page_urls_when_one_new_and_one_old_wiki_event_expect_one_url(self):
page1_url = 'http://host.com/user/repo/wiki/page1'
page2_url = 'http://host.com/user/repo/wiki/page2'
cut = sync.GitEvents()
def moc_get_page_of_events(self, page=1, etag=True):
return [{'id': '6', 'type': 'gollumEvent', 'pages': [{'html_url': page2_url}]}, {'id': '5', 'type': 'gollumEvent', 'pages': [{'html_url': page1_url}]}]
cut.get_page_of_events = types.MethodType(moc_get_page_of_events, cut)
cut.last_event = 5
actual = cut.get_changed_page_urls()
self.assertEqual(actual, [page2_url])
def test_get_changed_page_urls_when_two_new_events_on_two_result_pages_expect_two_urls(self):
page1_url = 'http://host.com/user/repo/wiki/page1'
page2_url = 'http://host.com/user/repo/wiki/page2'
cut = sync.GitEvents()
cut.last_event = 4
def moc_get_page_of_events(self, page=1, etag=True):
print "PAGE", page
if page == 1:
return [{'id': '6', 'type': 'gollumEvent', 'pages': [{'html_url': page2_url}]}]
if page == 2:
return [{'id': '5', 'type': 'gollumEvent', 'pages': [{'html_url': page1_url}]}, {'id': '4', 'type': 'add'}]
cut.get_page_of_events = types.MethodType(moc_get_page_of_events, cut)
actual = cut.get_changed_page_urls()
self.assertIn(page1_url, actual)
self.assertIn(page2_url, actual)
self.assertEqual(len(actual), 2)
def test_get_changed_page_urls_when_no_events_expect_no_urls(self):
def moc_get_page_of_events(self, page=1, etag=True):
return []
cut = sync.GitEvents()
cut.get_page_of_events = types.MethodType(moc_get_page_of_events, cut)
cut.last_event = 5
actual = cut.get_changed_page_urls()
self.assertEqual(actual, [])
if __name__ == '__main__':
unittest.main()