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
274 lines (206 loc) · 8.06 KB
/
Copy pathtest_users.py
File metadata and controls
274 lines (206 loc) · 8.06 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
import pytest
import github3
from . import helper
url_for = helper.create_url_helper(
'https://api.github.com/users/octocat'
)
github_url_for = helper.create_url_helper(
'https://api.github.com'
)
key_url_for = helper.create_url_helper(
'https://api.github.com/user/keys'
)
get_authenticated_user_example_data = helper.create_example_data_helper(
'authenticated_user_example'
)
get_users_example_data = helper.create_example_data_helper('users_example')
get_user_key_example_data = helper.create_example_data_helper(
'user_key_example'
)
example_data = get_users_example_data()
class TestUser(helper.UnitHelper):
"""Test methods on User class."""
described_class = github3.users.User
example_data = get_users_example_data()
def test_equality(self):
"""Show that two instances are equal."""
user = github3.users.User(get_users_example_data())
self.instance == user
user._uniq += 1
assert self.instance != user
def test_str(self):
"""Show that instance string is formatted correctly."""
assert str(self.instance) == 'octocat'
assert repr(self.instance) == '<User [octocat:monalisa octocat]>'
def test_is_assignee_on(self):
"""Verify the request for checking if user can be assignee."""
self.instance.is_assignee_on('octocat', 'hello-world')
self.session.get.assert_called_once_with(
github_url_for('repos/octocat/hello-world/assignees/octocat')
)
def test_is_following(self):
"""Verify request for checking if a user is following a user."""
self.instance.is_following('sigmavirus24')
self.session.get.assert_called_once_with(
url_for('/following/sigmavirus24')
)
class TestUserKeyRequiresAuth(helper.UnitRequiresAuthenticationHelper):
"""Test that ensure certain methods on Key class requires auth."""
described_class = github3.users.Key
example_data = get_user_key_example_data()
def test_update(self):
"""Test that updating a key requires authentication."""
self.assert_requires_auth(self.instance.update, title='New Title',
key='Fake key')
def test_delete(self):
"""Test that deleting a key requires authentication."""
self.assert_requires_auth(self.instance.delete)
class TestUserKey(helper.UnitHelper):
"""Test methods on Key class."""
described_class = github3.users.Key
example_data = get_user_key_example_data()
def test_equality(self):
"""Show that two instances of Key are equal."""
key = github3.users.Key(get_user_key_example_data())
assert self.instance == key
key._uniq += "cruft"
assert self.instance != key
def test_repr(self):
"""Show instance string is formatted properly."""
assert str(self.instance) == self.instance.key
assert repr(self.instance).startswith('<User Key')
def test_delete(self):
"""Test the request for deleting key."""
self.instance.delete()
assert self.session.delete.called is True
def test_update(self):
"""Test the request for updating a key."""
data = {
'title': 'New Title',
'key': 'Fake key'
}
self.instance.update(**data)
self.patch_called_with(
key_url_for('1'),
data=data
)
class TestUserIterators(helper.UnitIteratorHelper):
"""Test User methods that return iterators."""
described_class = github3.users.User
example_data = example_data.copy()
def test_events(self):
"""Test the request to retrieve a user's events."""
i = self.instance.events()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('events'),
params={'per_page': 100},
headers={}
)
def test_followers(self):
"""Test the request to retrieve follwers."""
f = self.instance.followers()
self.get_next(f)
self.session.get.assert_called_once_with(
url_for('followers'),
params={'per_page': 100},
headers={}
)
def test_following(self):
"""Test the request to retrieve users a user is following."""
i = self.instance.following()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('following'),
params={'per_page': 100},
headers={}
)
def test_keys(self):
"""Test the request to retrieve a user's public keys."""
i = self.instance.keys()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('keys'),
params={'per_page': 100},
headers={}
)
def test_organization_events(self):
"""Test the request to retrieve a user's organization events."""
i = self.instance.organization_events('org-name')
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('events/orgs/org-name'),
params={'per_page': 100},
headers={}
)
def test_organization_events_requires_an_org(self):
"""Test that organization_events will ignore empty org names."""
i = self.instance.organization_events(None)
with pytest.raises(StopIteration):
next(i)
def test_organizations(self):
"""Test the request to retrieve the orgs a user belongs to."""
i = self.instance.organizations()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('orgs'),
params={'per_page': 100},
headers={}
)
def test_received_events(self):
"""Test the request to retrieve the events a user receives."""
i = self.instance.received_events()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('received_events'),
params={'per_page': 100},
headers={}
)
def test_received_events_public_only(self):
"""Test the public request to retrieve the events a user received."""
i = self.instance.received_events(True)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('received_events/public'),
params={'per_page': 100},
headers={}
)
def test_starred_repositories(self):
"""Test the request to retrieve a user's starred repos."""
i = self.instance.starred_repositories()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('starred'),
params={'per_page': 100},
headers={
'Accept': 'application/vnd.github.v3.star+json'
}
)
def test_subscriptions(self):
"""Test the request to retrieve a user's subscriptions."""
i = self.instance.subscriptions()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('subscriptions'),
params={'per_page': 100},
headers={}
)
class TestUsersRequiresAuth(helper.UnitRequiresAuthenticationHelper):
"""Test that ensure certain methods on the User class requires auth."""
described_class = github3.users.User
example_data = example_data.copy()
def test_organization_events(self):
"""Test that #organization_events requires authentication."""
with pytest.raises(github3.GitHubError):
self.instance.organization_events('foo')
class TestPlan(helper.UnitGitHubObjectHelper):
"""Test for methods on Plan class."""
described_class = github3.users.Plan
example_data = get_authenticated_user_example_data()['plan']
def test_str(self):
"""Show that the instance string is formatted correctly."""
assert str(self.instance) == self.instance.name
assert repr(self.instance) == '<Plan [{0}]>'.format(self.instance.name)
def test_is_free(self):
"""Show that user can check if the plan is free."""
assert self.instance.is_free() is False