diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2020-04-17 01:41:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 01:41:55 +0200 |
commit | dad505c5e6aac3081ed796227e8f21d28b217ea0 (patch) | |
tree | f394d13a8fff9922d9eee4b71d86f5fa105a1a8b /gitlab/tests | |
parent | 0c3b717f9376668696ad13b6b481f28ab3c03abf (diff) | |
parent | c20f5f15de84d1b1bbb12c18caf1927dcfd6f393 (diff) | |
download | gitlab-dad505c5e6aac3081ed796227e8f21d28b217ea0.tar.gz |
Merge pull request #1075 from python-gitlab/feat/available-services
feat(services): add project service list API
Diffstat (limited to 'gitlab/tests')
-rw-r--r-- | gitlab/tests/objects/test_projects.py | 126 |
1 files changed, 125 insertions, 1 deletions
diff --git a/gitlab/tests/objects/test_projects.py b/gitlab/tests/objects/test_projects.py index 48347f9..6a2840a 100644 --- a/gitlab/tests/objects/test_projects.py +++ b/gitlab/tests/objects/test_projects.py @@ -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.""" @@ -169,7 +265,7 @@ class TestProject(unittest.TestCase): "http://localhost", private_token="private_token", ssl_verify=True, - api_version=4, + api_version="4", ) self.project = self.gl.projects.get(1, lazy=True) @@ -356,3 +452,31 @@ class TestProjectRemoteMirrors(TestProject): 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) |