8000 Created unit tests for repository.create_pull_from_issue · pythonthings/github3.py@df99f5e · GitHub
[go: up one dir, main page]

Skip to content

Commit df99f5e

Browse files
Created unit tests for repository.create_pull_from_issue
1 parent 01cb702 commit df99f5e

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

tests/unit/test_repos_repo.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from github3 import GitHubError
66
from github3.null import NullObject
77
from github3.repos.repo import Repository
8+
from github3.models import GitHubCore
89

910
from . import helper
1011

@@ -248,19 +249,65 @@ def test_create_milestone_accepted_state(self):
248249
}
249250
)
250251

251-
def test_create_pull(self):
252+
def test_create_pull_private_required_data(self):
253+
"""Verify the request for creating a pull request."""
254+
with helper.mock.patch.object(GitHubCore, '_remove_none') as rm_none:
255+
data = {}
256+
self.instance._create_pull(data)
257+
rm_none.assert_called_once_with({})
258+
assert self.session.post.called is False
259+
260+
def test_create_pull_private(self):
252261
"""Verify the request for creating a pull request."""
253262
data = {
254263
'title': 'foo',
255264
'base': 'master',
256265
'head': 'feature_branch'
257266
}
258-
self.instance.create_pull(**data)
267+
self.instance._create_pull(data)
259268
self.post_called_with(
260269
url_for('pulls'),
261270
data=data
262271
)
263272

273+
def test_create_pull(self):
274+
"""Verify the request for creating a pull request."""
275+
data = {
276+
'title': 'foo',
277+
'base': 'master',
278+
'head': 'feature_branch',
279+
'body': 'body'
280+
}
281+
with helper.mock.patch.object(Repository, '_create_pull') as pull:
282+
self.instance.create_pull(**data)
283+
pull.assert_called_once_with(
284+
data
285+
)
286+
287+
def test_create_pull_from_issue(self):
288+
"""Verify the request for creating a pull request from an issue."""
289+
with helper.mock.patch.object(Repository, '_create_pull') as pull:
290+
data = {
291+
'issue': 1,
292+
'base': 'master',
293+
'head': 'feature_branch'
294+
}
295+
self.instance.create_pull_from_issue(
296+
**data
297+
)
298+
pull.assert_called_once_with(data)
299+
300+
def test_create_pull_from_issue_required_issue_number(self):
301+
"""Verify the request for creating a pull request from an issue."""
302+
with helper.mock.patch.object(Repository, '_create_pull') as pull:
303+
pull_request = self.instance.create_pull_from_issue(
304+
issue=-1,
305+
base='master',
306+
head='feature_branch'
307+
)
308+
assert pull.called is False
309+
assert pull_request is None
310+
264311
def test_create_ref(self):
265312
"""Verify the request to create a reference."""
266313
self.instance.create_ref('refs/heads/foo', 'my-fake-sha')
@@ -903,6 +950,17 @@ def test_create_pull(self):
903950
with pytest.raises(GitHubError):
904951
self.instance.create_pull(title='foo', base='master')
905952

953+
def test_create_pull_from_issue(self):
954+
"""
955+
Verify that creating a pull request from issue requires authentication.
956+
"""
957+
with pytest.raises(GitHubError):
958+
self.instance.create_pull_from_issue(
959+
issue=1,
960+
title='foo',
961+
base='master'
962+
)
963+
906964
def test_hooks(self):
907965
"""Show that a user must be authenticated to list hooks."""
908966
with pytest.raises(GitHubError):

0 commit comments

Comments
 (0)
0