Skip to content

Commit 9032649

Browse files
committed
feat(services): add project service list API
Can be used to list available services It was introduced in GitLab 12.7
1 parent c7c431a commit 9032649

File tree

3 files changed

+134
-2
lines changed

3 files changed

+134
-2
lines changed

docs/gl_objects/projects.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ Get a service::
608608
# display its status (enabled/disabled)
609609
print(service.active)
610610

611+
List active project services::
612+
613+
service = project.services.list()
614+
611615
List the code names of available services (doesn't return objects)::
612616

613617
services = project.services.available()

gitlab/tests/objects/test_projects.py

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,106 @@ def resp_update_remote_mirror(url, request):
161161
return response(200, content, headers, None, 5, request)
162162

163163

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+
164264
class TestProject(unittest.TestCase):
165265
"""Base class for GitLab Project tests."""
166266

@@ -169,7 +269,7 @@ def setUp(self):
169269
"http://localhost",
170270
private_token="private_token",
171271
ssl_verify=True,
172-
api_version=4,
272+
api_version="4",
173273
)
174274
self.project = self.gl.projects.get(1, lazy=True)
175275

@@ -356,3 +456,31 @@ def test_update_project_remote_mirror(self):
356456
mirror.save()
357457
self.assertEqual(mirror.update_status, "finished")
358458
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)

gitlab/v4/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3995,7 +3995,7 @@ class ProjectService(SaveMixin, ObjectDeleteMixin, RESTObject):
39953995
pass
39963996

39973997

3998-
class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, RESTManager):
3998+
class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTManager):
39993999
_path = "/projects/%(project_id)s/services"
40004000
_from_parent_attrs = {"project_id": "id"}
40014001
_obj_cls = ProjectService

0 commit comments

Comments
 (0)