forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pulls.py
More file actions
152 lines (115 loc) · 4.44 KB
/
Copy pathtest_pulls.py
File metadata and controls
152 lines (115 loc) · 4.44 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
import github3
from mock import patch
from tests.utils import BaseCase, load, expect
class TestPullRequest(BaseCase):
def __init__(self, methodName='runTest'):
super(TestPullRequest, self).__init__(methodName)
self.pull = github3.pulls.PullRequest(load('pull'))
self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
"pulls/18")
def setUp(self):
super(TestPullRequest, self).setUp()
self.pull = github3.pulls.PullRequest(self.pull.to_json(), self.g)
def test_equality(self):
p = github3.pulls.PullRequest(load('pull'))
expect(self.pull) == p
p.id = 'foo'
expect(self.pull) != p
def test_dest(self):
expect(repr(self.pull.base).startswith('<Base')).is_True()
def test_repr(self):
expect(repr(self.pull).startswith('<Pull Request'))
def test_close(self):
with expect.githuberror():
self.pull.close()
self.login()
with patch.object(github3.pulls.PullRequest, 'update') as up:
up.return_value = True
expect(self.pull.close()).is_True()
up.assert_called_once_with(
self.pull.title, self.pull.body, 'closed')
def test_diff(self):
self.response('archive')
self.get(self.api)
self.conf = {
'headers': {
'Accept': 'application/vnd.github.diff'
}
}
expect(self.pull.diff()) != ''
self.mock_assertions()
def test_is_merged(self):
self.response('', 204)
self.get(self.api + '/merge')
expect(self.pull.is_merged()).is_True()
self.mock_assertions()
self.response('', 404)
expect(self.pull.is_merged()).is_False()
self.mock_assertions()
def test_iter_comments(self):
self.response('review_comment', _iter=True)
self.get(self.api + '/comments')
c = next(self.pull.iter_comments())
expect(c).isinstance(
github3.pulls.ReviewComment)
self.mock_assertions()
expect(repr(c).startswith('<Review Comment')).is_True()
def test_iter_issue_comments(self):
pull = github3.pulls.PullRequest(load('pull19'))
self.response('pull19_comment', _iter=True)
self.get(pull.links['comments'])
c = next(pull.iter_issue_comments())
expect(c).isinstance(
github3.issues.comment.IssueComment)
self.mock_assertions()
expect(repr(c).startswith('<Issue Comment')).is_True()
def test_iter_comits(self):
self.response('commit', _iter=True)
self.get(self.api + '/commits')
expect(next(self.pull.iter_commits())).isinstance(github3.git.Commit)
self.mock_assertions()
def test_iter_files(self):
self.response('pull_file', _iter=True)
self.get(self.api + '/files')
f = next(self.pull.iter_files())
expect(f).isinstance(github3.pulls.PullFile)
self.mock_assertions()
expect(repr(f).startswith('<Pull Request File')).is_True()
def test_merge(self):
self.response('merge', 200)
self.put(self.api + '/merge')
self.conf = {'data': None}
with expect.githuberror():
self.pull.merge()
self.not_called()
self.login()
expect(self.pull.merge()).is_True()
self.mock_assertions()
self.conf['data'] = {'commit_message': 'Merged'}
expect(self.pull.merge('Merged')).is_True()
self.mock_assertions()
def test_patch(self):
self.response('archive', 200)
self.get(self.api)
self.conf = {'headers': {'Accept': 'application/vnd.github.patch'}}
expect(self.pull.patch()) != ''
self.mock_assertions()
def test_reopen(self):
with expect.githuberror():
self.pull.reopen()
self.login()
with patch.object(github3.pulls.PullRequest, 'update') as up:
self.pull.reopen()
up.assert_called_once_with(
self.pull.title, self.pull.body, 'open')
def test_update(self):
self.response('pull', 200)
self.patch(self.api)
self.conf = {'data': {'title': 't', 'body': 'b', 'state': 'open'}}
with expect.githuberror():
self.pull.update()
self.login()
expect(self.pull.update()).is_False()
self.not_called()
expect(self.pull.update('t', 'b', 'open')).is_True()
self.mock_assertions()