Skip to content

Feat/available services #1075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/gl_objects/projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ Get a service::
# display its status (enabled/disabled)
print(service.active)

List active project services::

service = project.services.list()

List the code names of available services (doesn't return objects)::

services = project.services.available()
Expand Down
126 changes: 125 additions & 1 deletion gitlab/tests/objects/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,102 @@ def resp_update_remote_mirror(url, request):
return response(200, content, headers, None, 5, request)


@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/projects/1/services/pipelines-email",
method="put",
)
def resp_update_service(url, request):
"""Mock for Service update PUT response."""
content = """{
"id": 100152,
"title": "Pipelines emails",
"slug": "pipelines-email",
"created_at": "2019-01-14T08:46:43.637+01:00",
"updated_at": "2019-07-01T14:10:36.156+02:00",
"active": true,
"commit_events": true,
"push_events": true,
"issues_events": true,
"confidential_issues_events": true,
"merge_requests_events": true,
"tag_push_events": true,
"note_events": true,
"confidential_note_events": true,
"pipeline_events": true,
"wiki_page_events": true,
"job_events": true,
"comment_on_event_enabled": true,
"project_id": 1
}"""
content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)


@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/projects/1/services/pipelines-email",
method="get",
)
def resp_get_service(url, request):
"""Mock for Service GET response."""
content = """{
"id": 100152,
"title": "Pipelines emails",
"slug": "pipelines-email",
"created_at": "2019-01-14T08:46:43.637+01:00",
"updated_at": "2019-07-01T14:10:36.156+02:00",
"active": true,
"commit_events": true,
"push_events": true,
"issues_events": true,
"confidential_issues_events": true,
"merge_requests_events": true,
"tag_push_events": true,
"note_events": true,
"confidential_note_events": true,
"pipeline_events": true,
"wiki_page_events": true,
"job_events": true,
"comment_on_event_enabled": true,
"project_id": 1
}"""
content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)


@urlmatch(
scheme="http", netloc="localhost", path="/api/v4/projects/1/services", method="get",
)
def resp_get_active_services(url, request):
"""Mock for active Services GET response."""
content = """[{
"id": 100152,
"title": "Pipelines emails",
"slug": "pipelines-email",
"created_at": "2019-01-14T08:46:43.637+01:00",
"updated_at": "2019-07-01T14:10:36.156+02:00",
"active": true,
"commit_events": true,
"push_events": true,
"issues_events": true,
"confidential_issues_events": true,
"merge_requests_events": true,
"tag_push_events": true,
"note_events": true,
"confidential_note_events": true,
"pipeline_events": true,
"wiki_page_events": true,
"job_events": true,
"comment_on_event_enabled": true,
"project_id": 1
}]"""
content = content.encode("utf-8")
return response(200, content, headers, None, 5, request)


class TestProject(unittest.TestCase):
"""Base class for GitLab Project tests."""

Expand All @@ -169,7 +265,7 @@ def setUp(self):
"http://localhost",
private_token="private_token",
ssl_verify=True,
api_version=4,
api_version="4",
)
self.project = self.gl.projects.get(1, lazy=True)

Expand Down Expand Up @@ -356,3 +452,31 @@ def test_update_project_remote_mirror(self):
mirror.save()
self.assertEqual(mirror.update_status, "finished")
self.assertTrue(mirror.only_protected_branches)


class TestProjectServices(TestProject):
@with_httmock(resp_get_active_services)
def test_list_active_services(self):
services = self.project.services.list()
self.assertIsInstance(services, list)
self.assertIsInstance(services[0], ProjectService)
self.assertTrue(services[0].active)
self.assertTrue(services[0].push_events)

def test_list_available_services(self):
services = self.project.services.available()
self.assertIsInstance(services, list)
self.assertIsInstance(services[0], str)

@with_httmock(resp_get_service)
def test_get_service(self):
service = self.project.services.get("pipelines-email")
self.assertIsInstance(service, ProjectService)
self.assertEqual(service.push_events, True)

@with_httmock(resp_get_service, resp_update_service)
def test_update_service(self):
service = self.project.services.get("pipelines-email")
service.issues_events = True
service.save()
self.assertEqual(service.issues_events, True)
Loading