@@ -161,6 +161,106 @@ def resp_update_remote_mirror(url, request):
161
161
return response (200 , content , headers , None , 5 , request )
162
162
163
163
164
+ @urlmatch (
165
+ scheme = "http" ,
166
+ netloc = "localhost" ,
167
+ path = "/api/v4/projects/1/services/pipelines-email" ,
168
+ method = "put" ,
169
+ )
170
+ def resp_update_service (url , request ):
171
+ """Mock for Service update PUT response."""
172
+ content = """{
173
+ "id": 100152,
174
+ "title": "Pipelines emails",
175
+ "slug": "pipelines-email",
176
+ "created_at": "2019-01-14T08:46:43.637+01:00",
177
+ "updated_at": "2019-07-01T14:10:36.156+02:00",
178
+ "active": true,
179
+ "commit_events": true,
180
+ "push_events": true,
181
+ "issues_events": true,
182
+ "confidential_issues_events": true,
183
+ "merge_requests_events": true,
184
+ "tag_push_events": true,
185
+ "note_events": true,
186
+ "confidential_note_events": true,
187
+ "pipeline_events": true,
188
+ "wiki_page_events": true,
189
+ "job_events": true,
190
+ "comment_on_event_enabled": true,
191
+ "project_id": 1
192
+ }"""
193
+ content = content .encode ("utf-8" )
194
+ return response (200 , content , headers , None , 5 , request )
195
+
196
+
197
+ @urlmatch (
198
+ scheme = "http" ,
199
+ netloc = "localhost" ,
200
+ path = "/api/v4/projects/1/services/pipelines-email" ,
201
+ method = "get" ,
202
+ )
203
+ def resp_get_service (url , request ):
204
+ """Mock for Service GET response."""
205
+ content = """{
206
+ "id": 100152,
207
+ "title": "Pipelines emails",
208
+ "slug": "pipelines-email",
209
+ "created_at": "2019-01-14T08:46:43.637+01:00",
210
+ "updated_at": "2019-07-01T14:10:36.156+02:00",
211
+ "active": true,
212
+ "commit_events": true,
213
+ "push_events": true,
214
+ "issues_events": true,
215
+ "confidential_issues_events": true,
216
+ "merge_requests_events": true,
217
+ "tag_push_events": true,
218
+ "note_events": true,
219
+ "confidential_note_events": true,
220
+ "pipeline_events": true,
221
+ "wiki_page_events": true,
222
+ "job_events": true,
223
+ "comment_on_event_enabled": true,
224
+ "project_id": 1
225
+ }"""
226
+ content = content .encode ("utf-8" )
227
+ return response (200 , content , headers , None , 5 , request )
228
+
229
+
230
+ @urlmatch (
231
+ scheme = "http" ,
232
+ netloc = "localhost" ,
233
+ path = "/api/v4/projects/1/services" ,
234
+ method = "get" ,
235
+ )
236
+ def resp_get_active_services (url , request ):
237
+ """Mock for Service update PUT response."""
238
+ content = """[{
239
+ "id": 100152,
240
+ "title": "Pipelines emails",
241
+ "slug": "pipelines-email",
242
+ "created_at": "2019-01-14T08:46:43.637+01:00",
243
+ "updated_at": "2019-07-01T14:10:36.156+02:00",
244
+ "active": true,
245
+ "commit_events": true,
246
+ "push_events": true,
247
+ "issues_events": true,
248
+ "confidential_issues_events": true,
249
+ "merge_requests_events": true,
250
+ "tag_push_events": true,
251
+ "note_events": true,
252
+ "confidential_note_events": true,
253
+ "pipeline_events": true,
254
+ "wiki_page_events": true,
255
+ "job_events": true,
256
+ "comment_on_event_enabled": true,
257
+ "project_id": 1
258
+ }]"""
259
+ content = content .encode ("utf-8" )
260
+ return response (200 , content , headers , None , 5 , request )
261
+
262
+
263
+
164
264
class TestProject (unittest .TestCase ):
165
265
"""Base class for GitLab Project tests."""
166
266
@@ -169,7 +269,7 @@ def setUp(self):
169
269
"http://localhost" ,
170
270
private_token = "private_token" ,
171
271
ssl_verify = True ,
172
- api_version = 4 ,
272
+ api_version = "4" ,
173
273
)
174
274
self .project = self .gl .projects .get (1 , lazy = True )
175
275
@@ -356,3 +456,31 @@ def test_update_project_remote_mirror(self):
356
456
mirror .save ()
357
457
self .assertEqual (mirror .update_status , "finished" )
358
458
self .assertTrue (mirror .only_protected_branches )
459
+
460
+
461
+ class TestProjectServices (TestProject ):
462
+ @with_httmock (resp_get_active_services )
463
+ def test_list_active_services (self ):
464
+ services = self .project .services .list ()
465
+ self .assertIsInstance (services , list )
466
+ self .assertIsInstance (services [0 ], ProjectService )
467
+ self .assertTrue (services [0 ].active )
468
+ self .assertTrue (services [0 ].push_events )
469
+
470
+ def test_list_available_services (self ):
471
+ services = self .project .services .available ()
472
+ self .assertIsInstance (services , list )
473
+ self .assertIsInstance (services [0 ], str )
474
+
475
+ @with_httmock (resp_get_service )
476
+ def test_get_service (self ):
477
+ service = self .project .services .get ("pipelines-email" )
478
+ self .assertIsInstance (service , ProjectService )
479
+ self .assertEqual (service .push_events , True )
480
+
481
+ @with_httmock (resp_get_service , resp_update_service )
482
+ def test_update_service (self ):
483
+ service = self .project .services .get ("pipelines-email" )
484
+ service .issues_events = True
485
+ service .save ()
486
+ self .assertEqual (service .issues_events , True )
0 commit comments