8000 Test issue creation · n1k0/github3.py@a81dc50 · GitHub
[go: up one dir, main page]

Skip to content

Commit a81dc50

Browse files
committed
Test issue creation
1 parent 8b08bcf commit a81dc50

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

github3/repos.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def create_issue(self,
408408
body=None,
409409
assignee=None,
410410
milestone=None,
411-
labels=[]):
411+
labels=None):
412412
"""Creates an issue on this repository.
413413
414414
:param str title: (required), title of the issue
@@ -427,9 +427,12 @@ def create_issue(self,
427427
issue = {'title': title, 'body': body, 'assignee': assignee,
428428
'milestone': milestone, 'labels': labels}
429429
self._remove_none(issue)
430-
url = self._build_url('issues', base_url=self._api)
430+
json = None
431+
432+
if issue:
433+
url = self._build_url('issues', base_url=self._api)
434+
json = self._json(self._post(url, issue), 201)
431435

432-
json = self._json(self._post(url, issue), 201)
433436
return Issue(json, self) if json else None
434437

435438
@requires_auth

tests/test_repos.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,30 @@ def test_create_fork(self):
191191
expect(self.repo.create_fork('github3py')
192192
).isinstance(github3.repos.Repository)
193193
self.mock_assertions()
194+
195+
def test_create_issue(self):
196+
self.request.return_value = generate_response('issue', 201)
197+
title = 'Construct _api attribute on our own'
198+
self.args = ('post', self.api + 'issues')
199+
self.conf = {'data': {'title': title}}
200+
201+
with expect.githuberror():
202+
self.repo.create_issue(title)
203+
204+
self.login()
205+
expect(self.repo.create_issue(None)).is_None()
206+
expect(self.repo.create_issue(title)).isinstance(github3.issues.Issue)
207+
self.mock_assertions()
208+
209+
body = 'Fake body'
210+
self.conf['data'].update(body=body)
211+
expect(self.repo.create_issue(title, body)
212+
).isinstance(github3.issues.Issue)
213+
self.mock_assertions()
214+
215+
assignee, mile, labels = 'sigmavirus24', 1, ['bug', 'enhancement']
216+
self.conf['data'].update({'assignee': assignee, 'milestone': mile,
217+
'labels': labels})
218+
expect(self.repo.create_issue(title, body, assignee, mile, labels)
219+
).isinstance(github3.issues.Issue)
220+
self.mock_assertions()

0 commit comments

Comments
 (0)
0