Skip to content
Navigation Menu
{{ message }}
forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_users.py
More file actions
283 lines (221 loc) · 8.52 KB
/
Copy pathtest_users.py
File metadata and controls
283 lines (221 loc) · 8.52 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
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
import github3
from mock import patch
from tests.utils import (expect, BaseCase, load)
from datetime import datetime
class TestKey(BaseCase):
def __init__(self, methodName='runTest'):
super(TestKey, self).__init__(methodName)
self.key = github3.users.Key(load('key'))
self.api = "https://api.github.com/user/keys/10"
def setUp(self):
super(TestKey, self).setUp()
self.key = github3.users.Key(self.key.to_json(), self.g)
def test_equality(self):
k = github3.users.Key(self.key.to_json())
expect(self.key) == k
k.id += 1
expect(self.key) != k
def test_str(self):
expect(str(self.key)) == self.key.key
expect(repr(self.key).startswith('<User Key')).is_True()
def test_delete(self):
self.response('', 204)
self.delete(self.api)
with expect.githuberror():
self.key.delete()
self.not_called()
self.login()
expect(self.key.delete()).is_True()
self.mock_assertions()
def test_update(self):
self.response('key', 200)
self.patch(self.api)
self.conf = {
'data': {
'key': 'fakekey',
'title': 'New title',
}
}
with expect.githuberror():
self.key.update(None, None)
self.login()
expect(self.key.update(None, None)).is_False()
self.not_called()
expect(self.key.update(**self.conf['data'])).is_True()
self.mock_assertions()
class TestPlan(BaseCase):
def __init__(self, methodName='runTest'):
super(TestPlan, self).__init__(methodName)
self.plan = github3.users.Plan({
'name': 'free',
'space': 400,
'collaborators': 10,
'private_repos': 20,
})
def test_str(self):
expect(str(self.plan)) == self.plan.name
expect(repr(self.plan)) == '<Plan [free]>'
expect(self.plan.is_free()).is_True()
class TestUser(BaseCase):
def __init__(self, methodName='runTest'):
super(TestUser, self).__init__(methodName)
self.user = github3.users.User(load('user'))
self.api = "https://api.github.com/users/sigmavirus24"
def setUp(self):
super(TestUser, self).setUp()
self.user = github3.users.User(self.user.to_json(), self.g)
if hasattr(self.user.name, 'decode'):
self.user.name = self.user.name.decode('utf-8')
def test_refresh(self):
"""This sort of tests all instances of refresh for good measure."""
self.response('', 304)
self.get(self.api)
self.user.last_modified = last_modified = datetime.now().strftime(
'%a, %d %b %Y %H:%M:%S GMT'
)
self.user.etag = etag = '644b5b0155e6404a9cc4bd9d8b1ae730'
expected_headers = {
'If-Modified-Since': last_modified,
}
self.user.refresh(True)
self.request.assert_called_with('GET', self.api,
headers=expected_headers,
allow_redirects=True)
self.user.last_modified = None
expected_headers = {
'If-None-Match': etag
}
self.user.refresh(True)
self.request.assert_called_with('GET', self.api,
headers=expected_headers,
allow_redirects=True)
self.response('user', 200)
self.user.refresh()
self.mock_assertions()
def test_str(self):
expect(str(self.user)) == 'sigmavirus24'
expect(repr(self.user)) == '<User [sigmavirus24:Ian Cordasco]>'
def test_add_email_address(self):
with expect.githuberror():
self.user.add_email_address('foo')
self.not_called()
self.login()
with patch.object(github3.users.User, 'add_email_addresses') as p:
self.user.add_email_address('foo')
p.assert_called_once_with(['foo'])
def test_add_email_addresses(self):
self.response('emails', 201, _iter=True)
self.post(self.github_url + 'user/emails')
self.conf = {
'data': '["foo@bar.com"]',
}
with expect.githuberror():
self.user.add_email_addresses([])
self.not_called()
self.login()
self.user.add_email_addresses(['foo@bar.com'])
self.mock_assertions()
def test_delete_email_address(self):
with expect.githuberror():
self.user.delete_email_address('foo')
self.not_called()
self.login()
with patch.object(github3.users.User, 'delete_email_addresses') as p:
self.user.delete_email_address('foo')
p.assert_called_once_with(['foo'])
def test_delete_email_addresses(self):
self.response('', 204)
self.delete(self.github_url + 'user/emails')
self.conf = {
'data': '["foo@bar.com"]'
}
with expect.githuberror():
self.user.delete_email_addresses([])
self.not_called()
self.login()
expect(
self.user.delete_email_addresses(['foo@bar.com'])
).is_True()
self.mock_assertions()
def test_is_assignee_on(self):
self.response('', 404)
self.get(self.github_url + 'repos/abc/def/assignees/sigmavirus24')
expect(self.user.is_assignee_on('abc', 'def')).is_False()
self.mock_assertions()
def test_iter_events(self):
self.response('event', 200, _iter=True)
self.get(self.api + '/events')
expect(next(self.user.iter_events())).isinstance(github3.events.Event)
self.mock_assertions()
self.get(self.api + '/events/public')
next(self.user.iter_events(public=True))
self.mock_assertions()
def test_iter_followers(self):
self.response('user', 200, _iter=True)
self.get(self.api + '/followers')
expect(next(self.user.iter_followers())).isinstance(github3.users.User)
self.mock_assertions()
def test_iter_following(self):
self.response('user', 200, _iter=True)
self.get(self.api + '/following')
expect(next(self.user.iter_following())).isinstance(github3.users.User)
self.mock_assertions()
def test_iter_org_events(self):
self.response('event', 200, _iter=True)
self.get(self.api + '/events/orgs/foo')
with expect.raises(StopIteration):
next(self.user.iter_org_events(None))
self.not_called()
expect(next(self.user.iter_org_events('foo'))).isinstance(
github3.events.Event)
self.mock_assertions()
def test_iter_received_events(self):
self.response('event', 200, _iter=True)
self.get(self.api + '/received_events')
expect(next(self.user.iter_received_events())).isinstance(
github3.events.Event)
self.mock_assertions()
self.get(self.api + '/received_events/public')
next(self.user.iter_received_events(public=True))
self.mock_assertions()
def test_iter_starred(self):
self.response('repo', 200, _iter=True)
self.get(self.api + '/starred')
expect(next(self.user.iter_starred())).isinstance(
github3.repos.Repository)
self.mock_assertions()
def test_iter_subscriptions(self):
self.response('repo', 200, _iter=True)
self.get(self.api + '/subscriptions')
expect(next(self.user.iter_subscriptions())).isinstance(
github3.repos.Repository)
self.mock_assertions()
def test_iter_keys(self):
self.response('key', 200, _iter=True)
self.get(self.api + '/keys')
expect(next(self.user.iter_keys())).isinstance(github3.users.Key)
self.mock_assertions()
def test_update(self):
self.response('user', 200)
self.patch('https://api.github.com/user')
self.conf = {
'data': {
'name': 'Ian Cordasco',
'email': 'ian@cor.da.sc.o',
'blog': 'http://example.com/blog',
'hireable': True,
}
}
with expect.githuberror():
self.user.update()
self.not_called()
self.login()
expect(self.user.update(**self.conf['data'])).is_True()
self.mock_assertions()
self.response('', 404)
expect(self.user.update(**self.conf['data'])).is_False()
def test_equality(self):
u = github3.users.User(load('user'))
expect(self.user) == u
u.id += 1
expect(self.user) != u
You can’t perform that action at this time.
