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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from unittest import TestCase
import requests
from mock import patch, Mock
from pygithub3.services.repos import Repo, Collaborator, Commits
from pygithub3.resources.base import json
from pygithub3.tests.utils.base import (mock_response, mock_response_result,
mock_json)
from pygithub3.tests.utils.services import _
json.dumps = Mock(side_effect=mock_json)
json.loads = Mock(side_effect=mock_json)
@patch.object(requests.sessions.Session, 'request')
class TestRepoService(TestCase):
def setUp(self):
self.rs = Repo()
self.rs.set_user('octocat')
self.rs.set_repo('octocat_repo')
def test_LIST_without_user(self, request_method):
request_method.return_value = mock_response_result()
self.rs.set_user('')
self.rs.list().all()
self.assertEqual(request_method.call_args[0], ('get', _('user/repos')))
def test_LIST_with_user_in_args(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list('octoc').all()
self.assertEqual(request_method.call_args[0],
('get', _('users/octoc/repos')))
def test_LIST_with_user_in_service(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list().all()
self.assertEqual(request_method.call_args[0],
('get', _('users/octocat/repos')))
def test_LIST_filters(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list('octoc', type='public').all()
self.assertEqual(request_method.call_args[0],
('get', _('users/octoc/repos')))
self.assertEqual(request_method.call_args[1]['params']['type'],
'public')
def test_LIST_BY_ORG(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_by_org('org_name').all()
self.assertEqual(request_method.call_args[0],
('get', _('orgs/org_name/repos')))
def test_LIST_BY_ORG_filters(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_by_org('org_name', type='public').all()
self.assertEqual(request_method.call_args[0],
('get', _('orgs/org_name/repos')))
self.assertEqual(request_method.call_args[1]['params']['type'],
'public')
def test_CREATE(self, request_method):
request_method.return_value = mock_response('post')
self.rs.create({'name': 'test'})
self.assertEqual(request_method.call_args[0],
('post', _('user/repos')))
def test_CREATE_in_org(self, request_method):
request_method.return_value = mock_response('post')
self.rs.create({'name': 'test'}, in_org='org_name')
self.assertEqual(request_method.call_args[0],
('post', _('orgs/org_name/repos')))
def test_GET_with_repo_in_args(self, request_method):
request_method.return_value = mock_response()
self.rs.get(user='user', repo='repo')
self.assertEqual(request_method.call_args[0],
('get', _('repos/user/repo')))
def test_GET_with_repo_in_service(self, request_method):
request_method.return_value = mock_response()
self.rs.get()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo')))
def test_UPDATE_with_repo_in_args(self, request_method):
request_method.return_value = mock_response('patch')
self.rs.update({'name': 'test'}, user='user', repo='repo')
self.assertEqual(request_method.call_args[0],
('patch', _('repos/user/repo')))
def test_UPDATE_with_repo_in_service(self, request_method):
request_method.return_value = mock_response('patch')
self.rs.update({'name': 'test'})
self.assertEqual(request_method.call_args[0],
('patch', _('repos/octocat/octocat_repo')))
""" From here I stop to do '*in_args' and '*filter' tests, I consider
that I tested it enough... """
def test_LIST_contributors(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_contributors().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/contributors')))
def test_LIST_contributors_with_anonymous(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_contributors_with_anonymous().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/contributors')))
self.assertEqual(request_method.call_args[1]['params']['anom'], True)
def test_LIST_languages(self, request_method):
request_method.return_value = mock_response()
self.rs.list_languages()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/languages')))
def test_LIST_teams(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_teams().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/teams')))
def test_LIST_tags(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_tags().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/tags')))
def test_LIST_branches(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_branches().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/branches')))
@patch.object(requests.sessions.Session, 'request')
class TestCollaboratorsService(TestCase):
def setUp(self):
self.cs = Collaborator()
self.cs.set_user('octocat')
self.cs.set_repo('oc_repo')
def test_LIST(self, request_method):
request_method.return_value = mock_response_result()
self.cs.list().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/oc_repo/collaborators')))
def test_IS_colaborator(self, request_method):
request_method.return_value = mock_response()
self.cs.is_collaborator('user')
self.assertEqual(request_method.call_args[0],
('head', _('repos/octocat/oc_repo/collaborators/user')))
def test_ADD(self, request_method):
self.cs.add('user')
self.assertEqual(request_method.call_args[0],
('put', _('repos/octocat/oc_repo/collaborators/user')))
def test_DELETE(self, request_method):
request_method.return_value = mock_response('delete')
self.cs.delete('user')
self.assertEqual(request_method.call_args[0],
('delete', _('repos/octocat/oc_repo/collaborators/user')))
@patch.object(requests.sessions.Session, 'request')
class TestCommitsService(TestCase):
def setUp(self):
self.cs = Commits(user='oct', repo='re_oct')
"""
def test_LIST(self, request_method):
request_method.return_value = mock_response_result()
self.cs.list().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/oct/re_oct/commits')))
"""
def test_GET(self, request_method):
request_method.return_value = mock_response()
self.cs.get('e3bc')
self.assertEqual(request_method.call_args[0],
('get', _('repos/oct/re_oct/commits/e3bc')))
def test_LIST_comments(self, request_method):
request_method.return_value = mock_response_result()
self.cs.list_comments().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/oct/re_oct/comments')))
def test_LIST_comments_for_commit(self, request_method):
request_method.return_value = mock_response_result()
self.cs.list_comments(sha='e3bc').all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/oct/re_oct/commits/e3bc/comments')))
def test_CREATE_comment(self, request_method):
request_method.return_value = mock_response('post')
data = dict(body='some', commit_id='e2bc',
line=1, path='some.txt', position=1)
self.cs.create_comment(data, 'e3bc')
self.assertEqual(request_method.call_args[0],
('post', _('repos/oct/re_oct/commits/e3bc/comments')))
def test_GET_comment(self, request_method):
request_method.return_value = mock_response()
self.cs.get_comment(1)
self.assertEqual(request_method.call_args[0],
('get', _('repos/oct/re_oct/comments/1')))
def test_UPDATE_comment(self, request_method):
request_method.return_value = mock_response('patch')
self.cs.update_comment({'body': 'changed'}, 1)
self.assertEqual(request_method.call_args[0],
('patch', _('repos/oct/re_oct/comments/1')))
def test_COMPARE(self, request_method):
request_method.return_value = mock_response()
self.cs.compare('develop', 'master')
self.assertEqual(request_method.call_args[0],
('get', _('repos/oct/re_oct/compare/develop...master')))
def test_DELETE_comment(self, request_method):
request_method.return_value = mock_response('delete')
self.cs.delete_comment(1)
self.assertEqual(request_method.call_args[0],
('delete', _('repos/oct/re_oct/comments/1')))
|