Skip to content

Commit dad505c

Browse files
authored
Merge pull request #1075 from python-gitlab/feat/available-services
feat(services): add project service list API
2 parents 0c3b717 + c20f5f1 commit dad505c

File tree

3 files changed

+333
-29
lines changed

3 files changed

+333
-29
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: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,102 @@ 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", netloc="localhost", path="/api/v4/projects/1/services", method="get",
232+
)
233+
def resp_get_active_services(url, request):
234+
"""Mock for active Services GET response."""
235+
content = """[{
236+
"id": 100152,
237+
"title": "Pipelines emails",
238+
"slug": "pipelines-email",
239+
"created_at": "2019-01-14T08:46:43.637+01:00",
240+
"updated_at": "2019-07-01T14:10:36.156+02:00",
241+
"active": true,
242+
"commit_events": true,
243+
"push_events": true,
244+
"issues_events": true,
245+
"confidential_issues_events": true,
246+
"merge_requests_events": true,
247+
"tag_push_events": true,
248+
"note_events": true,
249+
"confidential_note_events": true,
250+
"pipeline_events": true,
251+
"wiki_page_events": true,
252+
"job_events": true,
253+
"comment_on_event_enabled": true,
254+
"project_id": 1
255+
}]"""
256+
content = content.encode("utf-8")
257+
return response(200, content, headers, None, 5, request)
258+
259+
164260
class TestProject(unittest.TestCase):
165261
"""Base class for GitLab Project tests."""
166262

@@ -169,7 +265,7 @@ def setUp(self):
169265
"http://localhost",
170266
private_token="private_token",
171267
ssl_verify=True,
172-
api_version=4,
268+
api_version="4",
173269
)
174270
self.project = self.gl.projects.get(1, lazy=True)
175271

@@ -356,3 +452,31 @@ def test_update_project_remote_mirror(self):
356452
mirror.save()
357453
self.assertEqual(mirror.update_status, "finished")
358454
self.assertTrue(mirror.only_protected_branches)
455+
456+
457+
class TestProjectServices(TestProject):
458+
@with_httmock(resp_get_active_services)
459+
def test_list_active_services(self):
460+
services = self.project.services.list()
461+
self.assertIsInstance(services, list)
462+
self.assertIsInstance(services[0], ProjectService)
463+
self.assertTrue(services[0].active)
464+
self.assertTrue(services[0].push_events)
465+
466+
def test_list_available_services(self):
467+
services = self.project.services.available()
468+
self.assertIsInstance(services, list)
469+
self.assertIsInstance(services[0], str)
470+
471+
@with_httmock(resp_get_service)
472+
def test_get_service(self):
473+
service = self.project.services.get("pipelines-email")
474+
self.assertIsInstance(service, ProjectService)
475+
self.assertEqual(service.push_events, True)
476+
477+
@with_httmock(resp_get_service, resp_update_service)
478+
def test_update_service(self):
479+
service = self.project.services.get("pipelines-email")
480+
service.issues_events = True
481+
service.save()
482+
self.assertEqual(service.issues_events, True)

0 commit comments

Comments
 (0)