Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d4a512

Browse files
committed
github3.issues is 100% test covered.
1 parent9ac4cd9 commit8d4a512

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)inlist(data.items()):
304-
ifvisNone:
305-
deldata[k]
303+
self._remove_none(data)
306304
ifdata:
307305
json=self._json(self._patch(self._api,data=dumps(data)),200)
308306
ifjson:
@@ -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-
returnself._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+
returnself._boolean(self._delete(url),204,404)
350351

351352
@requires_auth
352353
defremove_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
returnself.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-
returnself._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)forlinjson]ifjsonelse []
369371

370372
@requires_auth
371373
defreopen(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
withexpect.githuberror():
153153
self.i.assign('foo')
154154

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

158157
withpatch.object(github3.issues.Issue,'edit')ased:
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.numberifself.i.milestoneelseNone
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+
deftest_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+
deftest_create_comment(self):
193+
self.response('issue_comment',201)
194+
self.post(self.api+'/comments')
195+
self.conf= {'data': {'body':'comment body'}}
196+
197+
withexpect.githuberror():
198+
self.i.create_comment('')
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+
deftest_edit(self):
209+
self.response('issue',200)
210+
self.patch(self.api)
211+
self.conf= {'data': {'title':'new title'}}
212+
213+
withexpect.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+
deftest_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+
deftest_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+
deftest_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+
deftest_remove_label(self):
249+
self.response('',204)
250+
self.delete(self.api+'/labels/name')
251+
252+
withexpect.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+
deftest_remove_all_labels(self):
261+
withexpect.githuberror():
262+
self.i.remove_all_labels()
263+
264+
self.login()
265+
266+
withpatch.object(github3.issues.Issue,'replace_labels')asrl:
267+
rl.return_value= []
268+
expect(self.i.remove_all_labels())== []
269+
rl.assert_called_once_with([])
270+
271+
deftest_replace_labels(self):
272+
self.response('label',_iter=True)
273+
self.put(self.api+'/labels')
274+
self.conf= {'data':'["foo", "bar"]'}
275+
276+
withexpect.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+
deftest_reopen(self):
287+
withexpect.githuberror():
288+
self.i.reopen()
289+
290+
self.login()
291+
n=self.i.milestone.numberifself.i.milestoneelseNone
292+
u=self.i.assignee.loginifself.i.assigneeelseNone
293+
294+
withpatch.object(github3.issues.Issue,'edit')ased:
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)

[8]ページ先頭

©2009-2025 Movatter.jp