77from pygithub3 .exceptions import ValidationError
88from pygithub3 .tests .utils .core import TestCase
99from 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 )
1112from pygithub3 .tests .utils .base import (mock_response , mock_response_result ,
1213 mock_json )
1314from pygithub3 .tests .utils .services import _
2021class 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):
5857class 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):
9594class 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):
120119class 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' )
207200class 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