Skip to content
This repository was archived by the owner on Dec 17, 2019. It is now read-only.

Commit e383e91

Browse files
committed
Tests on services.issues working
Also fix some bugs
1 parent 4e07cc2 commit e383e91

File tree

7 files changed

+58
-64
lines changed

7 files changed

+58
-64
lines changed

pygithub3/requests/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def dumps(self):
2727
def parse(self):
2828
""" Parse body with schema-required rules """
2929
if not hasattr(self.content, 'items'):
30-
raise ValidationError("'%s' needs a content dictionary"
31-
% self.__class__.__name__)
30+
raise ValidationError("It needs a content dictionary (%s)" % (
31+
self.content, ))
3232
parsed = dict([(key, self.content[key]) for key in self.schema
3333
if key in self.content])
3434
for attr_required in self.required:

pygithub3/requests/issues/milestones.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class Create(Request):
2424

2525
def clean_body(self): # Test if API normalize it
2626
state = self.body.get('state', '')
27-
if state.lower() not in ('open', 'closed'):
27+
if state and state.lower() not in ('open', 'closed'):
2828
raise ValidationError("'state' must be 'open' or 'closed'")
29+
return self.body
2930

3031

3132
class Update(Create):

pygithub3/services/issues/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def list(self, filter='assigned', state='open', labels='', sort='created',
3535
"""
3636
params = dict(filter=filter, state=state, labels=labels, sort=sort,
3737
direction=direction)
38-
self._normalize_data('since', params)
38+
self._normalize_date('since', params)
3939
request = self.request_builder('issues.list')
4040
return self._get_result(request, **params)
4141

@@ -60,7 +60,7 @@ def list_by_repo(self, user=None, repo=None, milestone='*', state='open',
6060
"""
6161
params = dict(milestone=milestone, state=state, assignee=assignee,
6262
mentioned=mentioned, labels=labels, sort=sort, direction=direction)
63-
self._normalize_data('since', params)
63+
self._normalize_date('since', params)
6464
request = self.make_request('issues.list_by_repo', user=user,
6565
repo=repo)
6666
return self._get_result(request, **params)

pygithub3/services/issues/comments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def update(self, id, message, user=None, repo=None):
6868
.. note::
6969
Remember :ref:`config precedence`
7070
"""
71-
request = self.request_builder('issues.comments.edit', user=user,
71+
request = self.make_request('issues.comments.edit', user=user,
7272
repo=repo, id=id, body={'body': message})
7373
return self._patch(request)
7474

@@ -85,6 +85,6 @@ def delete(self, id, user=None, repo=None):
8585
.. note::
8686
Remember :ref:`config precedence`
8787
"""
88-
request = self.request_builder('issues.comments.delete', user=user,
88+
request = self.make_request('issues.comments.delete', user=user,
8989
repo=repo, id=id)
9090
self._delete(request)

pygithub3/services/issues/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def list_by_repo(self, user=None, repo=None):
2626
:param str repo: Repo name
2727
:returns: A :doc:`result`
2828
"""
29-
request = self.request_builder('issues.events.list_by_repo',
29+
request = self.make_request('issues.events.list_by_repo',
3030
user=user, repo=repo)
3131
return self._get_result(request)
3232

pygithub3/services/issues/labels.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def list_by_issue(self, number, user=None, repo=None):
102102
repo=repo, number=number)
103103
return self._get(request)
104104

105-
def add_to_issue(self, number, user=None, repo=None, *labels):
105+
def add_to_issue(self, number, labels, user=None, repo=None):
106106
""" Add labels to issue
107107
108108
:param int number: Issue number
@@ -142,7 +142,7 @@ def remove_from_issue(self, number, label, user=None, repo=None):
142142
name=label)
143143
return self._delete(request)
144144

145-
def replace_all(self, number, user=None, repo=None, *labels):
145+
def replace_all(self, number, labels, user=None, repo=None):
146146
""" Replace all labels for a issue
147147
148148
:param int number: Issue number
@@ -161,7 +161,7 @@ def replace_all(self, number, user=None, repo=None, *labels):
161161
user=user,
162162
repo=repo,
163163
number=number,
164-
body=labels,)
164+
body=map(str, labels))
165165
return self._put(request)
166166

167167
def remove_all(self, number, user=None, repo=None):

pygithub3/tests/services/test_issues.py

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from pygithub3.exceptions import ValidationError
88
from pygithub3.tests.utils.core import TestCase
99
from pygithub3.resources.base import json
10-
from pygithub3.services.issues import Issue, Comments, Events, Labels, Milestones
10+
from pygithub3.services.issues import (Issue, Comments, Events, Labels,
11+
Milestones)
1112
from pygithub3.tests.utils.base import (mock_response, mock_response_result,
1213
mock_json)
1314
from pygithub3.tests.utils.services import _
@@ -20,7 +21,7 @@
2021
class TestIssuesService(TestCase):
2122

2223
def setUp(self):
23-
self.isu = Issue()
24+
self.isu = Issue(user='octocat', repo='Hello-World')
2425

2526
def test_LIST_without_user(self, request_method):
2627
request_method.return_value = mock_response_result()
@@ -29,27 +30,25 @@ def test_LIST_without_user(self, request_method):
2930

3031
def test_LIST_by_repo(self, request_method):
3132
request_method.return_value = mock_response_result()
32-
self.isu.list_by_repo('octocat', 'Hello-World').all()
33+
self.isu.list_by_repo().all()
3334
self.assertEqual(request_method.call_args[0],
3435
('get', _('repos/octocat/Hello-World/issues')))
3536

3637
def test_GET(self, request_method):
3738
request_method.return_value = mock_response()
38-
self.isu.get('octocat', 'Hello-World', 1)
39+
self.isu.get(1)
3940
self.assertEqual(request_method.call_args[0],
4041
('get', _('repos/octocat/Hello-World/issues/1')))
4142

4243
def test_CREATE(self, request_method):
4344
request_method.return_value = mock_response('post')
44-
self.isu.create('octocat', 'Hello-World',
45-
dict(title='My issue', body='Fix this issue'))
45+
self.isu.create(dict(title='My issue', body='Fix this issue'))
4646
self.assertEqual(request_method.call_args[0],
4747
('post', _('repos/octocat/Hello-World/issues')))
4848

4949
def test_UPDATE(self, request_method):
5050
request_method.return_value = mock_response('patch')
51-
self.isu.update('octocat', 'Hello-World', 1,
52-
{'body': 'edited'})
51+
self.isu.update(1, {'body': 'edited'})
5352
self.assertEqual(request_method.call_args[0],
5453
('patch', _('repos/octocat/Hello-World/issues/1')))
5554

@@ -58,35 +57,35 @@ def test_UPDATE(self, request_method):
5857
class TestCommentService(TestCase):
5958

6059
def setUp(self):
61-
self.cs = Comments()
60+
self.cs = Comments(user='octocat', repo='Hello-World')
6261

6362
def test_LIST(self, request_method):
6463
request_method.return_value = mock_response_result()
65-
self.cs.list('octocat', 'Hello-World', 1).all()
64+
self.cs.list(1).all()
6665
self.assertEqual(request_method.call_args[0],
6766
('get', _('repos/octocat/Hello-World/issues/1/comments')))
6867

6968
def test_GET(self, request_method):
7069
request_method.return_value = mock_response()
71-
self.cs.get('octocat', 'Hello-World', 1)
70+
self.cs.get(1)
7271
self.assertEqual(request_method.call_args[0],
7372
('get', _('repos/octocat/Hello-World/issues/comments/1')))
7473

7574
def test_CREATE(self, request_method):
7675
request_method.return_value = mock_response('post')
77-
self.cs.create('octocat', 'Hello-World', 1, 'comment')
76+
self.cs.create(1, 'comment')
7877
self.assertEqual(request_method.call_args[0],
7978
('post', _('repos/octocat/Hello-World/issues/1/comments')))
8079

8180
def test_UPDATE(self, request_method):
8281
request_method.return_value = mock_response('patch')
83-
self.cs.update('octocat', 'Hello-World', 1, 'new comment')
82+
self.cs.update(1, 'new comment')
8483
self.assertEqual(request_method.call_args[0],
8584
('patch', _('repos/octocat/Hello-World/issues/comments/1')))
8685

8786
def test_DELETE(self, request_method):
8887
request_method.return_value = mock_response('delete')
89-
self.cs.delete('octocat', 'Hello-World', 1)
88+
self.cs.delete(1)
9089
self.assertEqual(request_method.call_args[0],
9190
('delete', _('repos/octocat/Hello-World/issues/comments/1')))
9291

@@ -95,23 +94,23 @@ def test_DELETE(self, request_method):
9594
class TestEventsService(TestCase):
9695

9796
def setUp(self):
98-
self.ev = Events()
97+
self.ev = Events(user='octocat', repo='Hello-World')
9998

10099
def test_LIST_by_issue(self, request_method):
101100
request_method.return_value = mock_response_result()
102-
self.ev.list_by_issue('octocat', 'Hello-World', 1).all()
101+
self.ev.list_by_issue(1).all()
103102
self.assertEqual(request_method.call_args[0],
104103
('get', _('repos/octocat/Hello-World/issues/1/events')))
105104

106105
def test_LIST_by_repo(self, request_method):
107106
request_method.return_value = mock_response_result()
108-
self.ev.list_by_repo('octocat', 'Hello-World').all()
107+
self.ev.list_by_repo().all()
109108
self.assertEqual(request_method.call_args[0],
110109
('get', _('repos/octocat/Hello-World/issues/events')))
111110

112111
def test_GET(self, request_method):
113112
request_method.return_value = mock_response()
114-
self.ev.get('octocat', 'Hello-World', 1)
113+
self.ev.get(1)
115114
self.assertEqual(request_method.call_args[0],
116115
('get', _('repos/octocat/Hello-World/issues/events/1')))
117116

@@ -120,121 +119,115 @@ def test_GET(self, request_method):
120119
class TestLabelsService(TestCase):
121120

122121
def setUp(self):
123-
self.lb = Labels()
122+
self.lb = Labels(user='octocat', repo='Hello-World')
124123

125124
def test_GET(self, request_method):
126125
request_method.return_value = mock_response()
127-
self.lb.get('octocat', 'Hello-World', 'bug')
126+
self.lb.get('bug')
128127
self.assertEqual(request_method.call_args[0],
129128
('get', _('repos/octocat/Hello-World/labels/bug')))
130129

131130
def test_CREATE(self, request_method):
132131
request_method.return_value = mock_response('post')
133-
self.lb.create('octocat', 'Hello-World', 'bug', 'FF0000')
132+
self.lb.create(dict(name='bug', color='FF0000'))
134133
self.assertEqual(request_method.call_args[0],
135134
('post', _('repos/octocat/Hello-World/labels')))
136135

137136
def test_CREATE_with_invalid_color(self, request_method):
138137
request_method.return_value = mock_response('post')
139138
# invalid color
140-
with self.assertRaises(ValidationError):
141-
args={'user': 'octocat',
142-
'repo': 'Hello-world',
143-
'name': 'bug',
144-
'color': 'FF00',}
145-
self.lb.create(**args)
139+
with self.assertRaises(ValidationError):
140+
args={'name': 'bug', 'color': 'FF00'}
141+
self.lb.create(args)
146142

147143
def test_UPDATE(self, request_method):
148144
request_method.return_value = mock_response('patch')
149-
self.lb.update('octocat', 'Hello-World', 'bug', 'critical', 'FF0000')
145+
self.lb.update('bug', dict(name='critical', color='FF0000'))
150146
self.assertEqual(request_method.call_args[0],
151147
('patch', _('repos/octocat/Hello-World/labels/bug')))
152148

153149
def test_UPDATE_with_invalid_color(self, request_method):
154150
request_method.return_value = mock_response('post')
155151
# invalid color
156-
with self.assertRaises(ValidationError):
157-
args={'user': 'octocat',
158-
'repo': 'Hello-world',
159-
'name': 'bug',
160-
'new_name': 'critical',
152+
with self.assertRaises(ValidationError):
153+
args={'name': 'critical',
161154
'color': 'FF00',}
162-
self.lb.update(**args)
155+
self.lb.update('bug', args)
163156

164157
def test_DELETE(self, request_method):
165158
request_method.return_value = mock_response('delete')
166-
self.lb.delete('octocat', 'Hello-World', 'bug')
159+
self.lb.delete('bug')
167160
self.assertEqual(request_method.call_args[0],
168161
('delete', _('repos/octocat/Hello-World/labels/bug')))
169162

170-
def test_LIST_by_repo(self, request_method):
171-
request_method.return_value = mock_response()
172-
self.lb.list_by_repo('octocat', 'Hello-World')
173-
self.assertEqual(request_method.call_args[0],
174-
('get', _('repos/octocat/Hello-World/labels')))
175-
176163
def test_LIST_by_issue(self, request_method):
177164
request_method.return_value = mock_response()
178-
self.lb.list_by_issue('octocat', 'Hello-World', 1)
165+
self.lb.list_by_issue(1)
179166
self.assertEqual(request_method.call_args[0],
180167
('get', _('repos/octocat/Hello-World/issues/1/labels')))
181168

182169
def test_ADD_to_issue(self, request_method):
183170
request_method.return_value = mock_response('post')
184-
self.lb.add_to_issue('octocat', 'Hello-World', 1, ['bug', 'critical'])
171+
self.lb.add_to_issue(1, ('bug', 'critical'))
185172
self.assertEqual(request_method.call_args[0],
186173
('post', _('repos/octocat/Hello-World/issues/1/labels')))
187174

188175
def test_REMOVE_from_issue(self, request_method):
189176
request_method.return_value = mock_response('delete')
190-
self.lb.remove_from_issue('octocat', 'Hello-World', 1, 'bug')
177+
self.lb.remove_from_issue(1, 'bug')
191178
self.assertEqual(request_method.call_args[0],
192179
('delete', _('repos/octocat/Hello-World/issues/1/labels/bug')))
193180

194181
def test_REPLACE_all(self, request_method):
195-
self.lb.replace_all('octocat', 'Hello-World', 1, ['bug', 'critical'])
182+
self.lb.replace_all(1, ['bug', 'critical'])
196183
self.assertEqual(request_method.call_args[0],
197184
('put', _('repos/octocat/Hello-World/issues/1/labels')))
198185

199186
def test_REMOVE_all(self, request_method):
200187
request_method.return_value = mock_response('delete')
201-
self.lb.remove_all('octocat', 'Hello-World', 1)
188+
self.lb.remove_all(1)
202189
self.assertEqual(request_method.call_args[0],
203190
('delete', _('repos/octocat/Hello-World/issues/1/labels')))
204-
191+
192+
def test_LIST_by_milestone(self, request_method):
193+
request_method.return_value = mock_response_result()
194+
self.lb.list_by_milestone(1).all()
195+
self.assertEqual(request_method.call_args[0],
196+
('get', _('repos/octocat/Hello-World/milestones/1/labels')))
197+
205198

206199
@patch.object(requests.sessions.Session, 'request')
207200
class TestMilestonesService(TestCase):
208201

209202
def setUp(self):
210-
self.mi = Milestones()
203+
self.mi = Milestones(user='octocat', repo='Hello-World')
211204

212205
def test_LIST_by_repo(self, request_method):
213206
request_method.return_value = mock_response_result()
214-
self.mi.list('octocat', 'Hello-World').all()
207+
self.mi.list().all()
215208
self.assertEqual(request_method.call_args[0],
216209
('get', _('repos/octocat/Hello-World/milestones')))
217210

218211
def test_GET(self, request_method):
219212
request_method.return_value = mock_response()
220-
self.mi.get('octocat', 'Hello-World', 1)
213+
self.mi.get(1)
221214
self.assertEqual(request_method.call_args[0],
222215
('get', _('repos/octocat/Hello-World/milestones/1')))
223216

224217
def test_CREATE(self, request_method):
225218
request_method.return_value = mock_response('post')
226-
self.mi.create('octocat', 'Hello-World', 'title')
219+
self.mi.create(dict(title='test'))
227220
self.assertEqual(request_method.call_args[0],
228221
('post', _('repos/octocat/Hello-World/milestones')))
229222

230223
def test_UPDATE(self, request_method):
231224
request_method.return_value = mock_response('patch')
232-
self.mi.update('octocat', 'Hello-World', 1, 'critical')
225+
self.mi.update(1, dict(title='test'))
233226
self.assertEqual(request_method.call_args[0],
234227
('patch', _('repos/octocat/Hello-World/milestones/1')))
235228

236229
def test_DELETE(self, request_method):
237230
request_method.return_value = mock_response('delete')
238-
self.mi.delete('octocat', 'Hello-World', 1)
231+
self.mi.delete(1)
239232
self.assertEqual(request_method.call_args[0],
240233
('delete', _('repos/octocat/Hello-World/milestones/1')))

0 commit comments

Comments
 (0)