10000 github3.issues is 100% test covered. · davidmoss/github3.py@8d4a512 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d4a512

Browse files
committed
github3.issues is 100% test covered.
1 parent 9ac4cd9 commit 8d4a512

File tree

3 files changed

+138
-10
lines changed

3 files changed

+138
-10
lines changed

HISTORY.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,16 @@ History/Changelog
7373
return the same information. In the next version, the former will be
7474
removed.
7575

76-
- ``github3.issues.Issue.add_labels`` now returns the list of Labels on the
77-
issue instead of a boolean.
76+
- In github3.issues.Issue
77+
78+
- ``add_labels`` now returns the list of Labels on the issue instead of a
79+
boolean.
80+
81+
- ``remove_label`` now retuns a boolean.
82+
83+
- ``remove_all_labels`` and ``replace_labels`` now return lists. The former
84+
should return an empty list on a successful call. The latter should
85+
return a list of ``github3.issue.Label`` objects.
7886

7987
- Now we won't get spurious GitHubErrors on 404s, only on other expected
8088
errors whilst accessing the json in a response. All methods that return an

github3/issues.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,7 @@ def edit(self, title=None, body=None, assignee=None, state=None,
300300
json = None
301301
data = {'title': title, 'body': body, 'assignee': assignee,
302302
'state': state, 'milestone': milestone, 'labels': labels}
303-
for (k, v) in list(data.items()):
304-
if v is None:
305-
del data[k]
303+
self._remove_none(data)
306304
if data:
307305
json = self._json(self._patch(self._api, data=dumps(data)), 200)
308306
if json:
@@ -343,16 +341,19 @@ def remove_label(self, name):
343341
"""Removes label ``name`` from this issue.
344342
345343
:param str name: (required), name of the label to remove
346-
:returns: list of labels remaining
344+
:returns: bool
347345
"""
348346
url = self._build_url('labels', name, base_url=self._api)
349-
return self._json(self._delete(url), 200)
347+
# Docs say it should be a list of strings returned, practice says it
348+
# is just a 204/404 response. I'm tenatively changing this until I
349+
# hear back from Support.
350+
return self._boolean(self._delete(url), 204, 404)
350351

351352
@requires_auth
352353
def remove_all_labels(self):
353354
"""Remove all labels from this issue.
354355
355-
:returns: bool
356+
:returns: an empty list if successful
356357
"""
357358
# Can either send DELETE or [] to remove all labels
358359
return self.replace_labels([])
@@ -365,7 +366,8 @@ def replace_labels(self, labels):
365366
:returns: bool
366367
"""
367368
url = self._build_url('labels', base_url=self._api)
368-
return self._boolean(self._put(url, data=dumps(labels)), 200, 404)
369+
json = self._json(self._put(url, data=dumps(labels)), 200)
370+
return [Label(l, self) for l in json] if json else []
369371

370372
@requires_auth
371373
def reopen(self):

tests/test_issues.py

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,12 @@ def test_assign(self):
152152
with expect.githuberror():
153153
self.i.assign('foo')
154154

155-
self.not_called()
156155
self.login()
157156

158157
with patch.object(github3.issues.Issue, 'edit') as ed:
159158
ed.return_value = True
159+
expect(self.i.assign(None)).is_False()
160+
self.not_called()
160161
expect(self.i.assign('sigmavirus24')).is_True()
161162
n = self.i.milestone.number if self.i.milestone else None
162163
ed.assert_called_once_with(
@@ -179,3 +180,120 @@ def test_close(self):
179180
ed.assert_called_once_with(
180181
self.i.title, self.i.body, u, self.i.state, n, self.i.labels
181182
)
183+
184+
def test_comment(self):
185+
self.response('issue_comment')
186+
self.get(self.api[:-1] + 'comments/476476')
187+
188+
expect(self.i.comment('476476')).isinstance(
189+
github3.issues.IssueComment)
190+
self.mock_assertions()
191+
192+
def test_create_comment(self):
193+
self.response('issue_comment', 201)
194+
self.post(self.api + '/comments')
195+
self.conf = {'data': {'body': 'comment body'}}
196+
197+
with expect.githuberror():
198+
self.i.create_comment(' B41A ;')
199+
200+
self.login()
201+
expect(self.i.create_comment(None)).is_None()
202+
self.not_called()
203+
204+
expect(self.i.create_comment('comment body')).isinstance(
205+
github3.issues.IssueComment)
206+
self.mock_assertions()
207+
208+
def test_edit(self):
209+
self.response('issue', 200)
210+
self.patch(self.api)
211+
self.conf = {'data': {'title': 'new title'}}
212+
213+
with expect.githuberror():
214+
self.i.edit()
215+
216+
self.login()
217+
expect(self.i.edit()).is_False()
218+
self.not_called()
219+
220+
expect(self.i.edit('new title')).is_True()
221+
self.mock_assertions()
222+
223+
def test_is_closed(self):
224+
expect(self.i.is_closed()).is_True()
225+
226+
self.i.closed_at = None
227+
expect(self.i.is_closed()).is_True()
228+
229+
self.i.state = 'open'
230+
expect(self.i.is_closed()).is_False()
231+
232+
def test_iter_comments(self):
233+
self.response('issue_comment', _iter=True)
234+
self.get(self.api + '/comments')
235+
236+
expect(next(self.i.iter_comments())).isinstance(
237+
github3.issues.IssueComment)
238+
self.mock_assertions()
239+
240+
def test_iter_events(self):
241+
self.response('issue_event', _iter=True)
242+
self.get(self.api + '/events')
243+
244+
expect(next(self.i.iter_events())).isinstance(
245+
github3.issues.IssueEvent)
246+
self.mock_assertions()
247+
248+
def test_remove_label(self):
249+
self.response('', 204)
250+
self.delete(self.api + '/labels/name')
251+
252+
with expect.githuberror():
253+
self.i.remove_label('name')
254+
255+
self.not_called()
256+
self.login()
257+
expect(self.i.remove_label('name')).is_True()
258+
self.mock_assertions()
259+
260+
def test_remove_all_labels(self):
261+
with expect.githuberror():
262+
self.i.remove_all_labels()
263+
264+
self.login()
265+
266+
with patch.object(github3.issues.Issue, 'replace_labels') as rl:
267+
rl.return_value = []
268+
expect(self.i.remove_all_labels()) == []
269+
rl.assert_called_once_with([])
270+
271+
def test_replace_labels(self):
272+
self.response('label', _iter=True)
273+
self.put(self.api + '/labels')
274+
self.conf = {'data': '["foo", "bar"]'}
275+
276+
with expect.githuberror():
277+
self.i.replace_labels([])
278+
279+
self.not_called()
280+
self.login()
281+
282+
labels = self.i.replace_labels(['foo', 'bar'])
283+
expect(labels) != []
284+
expect(labels[0]).isinstance(github3.issues.Label)
285+
286+
def test_reopen(self):
287+
with expect.githuberror():
288+
self.i.reopen()
289+
290+
self.login()
291+
n = self.i.milestone.number if self.i.milestone else None
292+
u = self.i.assignee.login if self.i.assignee else None
293+
294+
with patch.object(github3.issues.Issue, 'edit') as ed:
295+
ed.return_value = True
296+
expect(self.i.reopen()).is_True()
297+
ed.assert_called_once_with(
298+
self.i.title, self.i.body, u, 'open', n, self.i.labels
299+
)

0 commit comments

Comments
 (0)
0