forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_github.py
More file actions
198 lines (168 loc) · 7.28 KB
/
Copy pathtest_github.py
File metadata and controls
198 lines (168 loc) · 7.28 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
import github3
from base import expect, expect_str, BaseTest
class TestGitHub(BaseTest):
def __init__(self, methodName='runTest'):
super(TestGitHub, self).__init__(methodName)
self.fake_auth = ('fake_user', 'fake_password')
self.fake_oauth = 'foobarbogusoauth'
def test_github(self):
expect(self.g).isinstance(github3.GitHub)
expect_str(repr(self.g))
def test_login(self):
# Test "regular" auth
self.g.login(*self.fake_auth)
h = github3.login(*self.fake_auth)
l = github3.GitHub(*self.fake_auth)
for i in [self.g, h, l]:
expect(self.fake_auth) == i._session.auth
def test_oauth(self):
# Test "oauth" auth
self.g.login(token=self.fake_oauth)
h = github3.login('', '', token=self.fake_oauth)
for i in [self.g, h]:
expect(i._session.headers['Authorization']) == 'token ' +\
self.fake_oauth
with expect.raises(github3.GitHubError):
self.g.user()
if self.auth:
expect(self._g.user()).is_not_None()
def test_gists(self):
# My gcd example
gist_id = 2648112
g = self.g.gist(gist_id)
if not g:
self.fail('Check gcd gist')
expect(g).isinstance(github3.gists.Gist)
with expect.raises(github3.GitHubError):
self.g.gist(-1)
for i in None, self.sigm:
expect(self.g.list_gists(i)) != []
if self.auth:
desc = 'Testing gist creation'
files = {'test.txt': {'content': 'Test contents'}}
gist = self._g.create_gist(desc, files, False)
expect(gist).is_not_None()
expect(gist.description) == desc
expect(gist.is_public()).is_False()
for g in gist.list_files():
expect(g.content) == files[g.name]['content']
expect(gist.delete()).is_True()
def test_following(self):
expect(self.g.list_followers('kennethreitz')) != []
expect(self.g.list_following('kennethreitz')) != []
with expect.raises(github3.GitHubError):
self.g.is_following(self.sigm)
self.g.follow(self.sigm)
self.g.unfollow(self.sigm)
self.g.list_followers()
self.g.list_following()
if self.auth:
expect(self._g.is_following(self.sigm)).isinstance(bool)
expect(self._g.follow(self.sigm)).isinstance(bool)
expect(self._g.unfollow(self.sigm)).isinstance(bool)
expect(self._g.list_followers()) != []
expect(self._g.list_following()) != []
def test_watching(self):
expect(self.g.list_watching(self.sigm)) != []
with expect.raises(github3.GitHubError):
self.g.watch(self.sigm, self.todo)
self.g.unwatch(self.sigm, self.todo)
self.g.list_watching()
self.g.is_watching(self.sigm, self.todo)
if self.auth:
expect(self._g.watch(self.sigm, self.todo)).isinstance(bool)
expect(self._g.unwatch(self.sigm, self.todo)).isinstance(bool)
expect(self._g.list_watching()) != []
expect(self._g.is_watching(self.sigm, self.todo)) != []
def test_issues(self):
title = 'Test issue for github3.py'
with expect.raises(github3.GitHubError):
# Try to create one without authenticating
self.g.create_issue(self.sigm, self.todo, title)
# Try to get individual ones
self.g.issue(self.sigm, self.todo, 2000)
self.g.list_user_issues()
i = self.g.issue(self.kr, 'requests', 1)
self.assertIsNotNone(i)
expect(i).isinstance(github3.issues.Issue)
expect(i.list_comments()) != []
# Test listing issues
list_issues = self.g.list_repo_issues
expect(list_issues(self.kr, 'requests')) != []
expect(list_issues(self.sigm, self.todo)).isinstance(list)
for f in ('assigned', 'created', 'mentioned'):
self.assertIsNotNone(list_issues(self.sigm, self.todo, f))
for s in ('open', 'closed'):
self.assertIsNotNone(list_issues(self.sigm, self.todo, state=s))
self.assertIsNotNone(list_issues(self.sigm, self.todo, state='closed',
labels='Bug,Enhancement'))
for s in ('created', 'updated', 'comments'):
self.assertIsNotNone(list_issues(self.sigm, self.todo, sort=s))
for d in ('asc', 'desc'):
self.assertIsNotNone(list_issues(self.sigm, self.todo,
state='closed', direction=d))
expect(list_issues(self.sigm, self.todo,
since='2011-01-01T00:00:01Z')).is_not_None()
if self.auth:
i = self._g.create_issue(self.gh3py, self.test_repo,
'Testing github3.py', 'Ignore this.')
expect(i).isinstance(github3.issues.Issue)
expect(i.close()).is_True()
def test_keys(self):
with expect.raises(github3.GitHubError):
self.g.create_key('Foo bar', 'bogus')
self.g.delete_key(2000)
self.g.get_key(2000)
self.g.list_keys()
# Need to find a way to make this work
#if self.auth:
# k = self._g.create_key('Foo bar', 'bogus')
# expect(k).isinstance(github3.user.Key)
def test_repos(self):
with expect.raises(github3.GitHubError):
self.g.create_repo('test_github3.py')
self.g.list_repos()
expect(self.g.list_repos(self.sigm)) != []
expect(self.g.repository(self.sigm, self.todo)).is_not_None()
def test_requires_auth(self):
with expect.raises(github3.GitHubError):
self.g.list_authorizations()
self.g.authorization(-1)
self.g.authorize('foo', 'bar', ['gist', 'user'])
def test_list_emails(self):
with expect.raises(github3.GitHubError):
self.g.list_emails()
def test_orgs(self):
expect(self.g.list_orgs(self.kr)) != []
expect(self.g.organization(self.gh3py)).is_not_None()
with expect.raises(github3.GitHubError):
self.g.list_orgs()
def test_markdown(self):
md = "# Header\n\nParagraph\n\n## Header 2\n\nParagraph"
reg = self.g.markdown(md)
raw = self.g.markdown(md, raw=True)
self.assertEqual(reg, raw)
def test_search(self):
expect(self.g.search_issues(self.sigm, self.todo, 'closed',
'todo')).is_not_None()
expect(self.g.search_users(self.sigm)).is_not_None()
def test_users(self):
with expect.raises(github3.GitHubError):
self.g.update_user()
self.g.user()
expect(self.g.user(self.sigm)).is_not_None()
def test_authorization(self):
with expect.raises(github3.GitHubError):
self.g.authorization(1000)
if not self.auth:
return
auth = self.g.authorize(self.user, self.pw, [])
expect(auth).isinstance(github3.github.Authorization)
auth_g = self._g.authorization(auth.id)
expect(auth_g).isinstance(github3.github.Authorization)
auth.delete()
del auth
auth = self._g.authorize(None, None, [])
expect(auth).isinstance(github3.github.Authorization)
auth.delete()