diff options
| author | Nejc Habjan <hab.nejc@gmail.com> | 2021-06-27 20:26:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-27 20:26:41 +0200 |
| commit | 6abf13a7e25e368da342e7d1da6cfc19915c2dfd (patch) | |
| tree | 260ab3034ff8a51dcfcb5d56805d1120dcd02f71 /tests/unit/objects | |
| parent | 33d342818599f403434e7024097449b6f21babc0 (diff) | |
| parent | 953f207466c53c28a877f2a88da9160acef40643 (diff) | |
| download | gitlab-6abf13a7e25e368da342e7d1da6cfc19915c2dfd.tar.gz | |
Merge pull request #1533 from sugonyak/add-group-hooks
feat(api): add group hooks
Diffstat (limited to 'tests/unit/objects')
| -rw-r--r-- | tests/unit/objects/test_hooks.py | 192 | ||||
| -rw-r--r-- | tests/unit/objects/test_projects.py | 25 |
2 files changed, 186 insertions, 31 deletions
diff --git a/tests/unit/objects/test_hooks.py b/tests/unit/objects/test_hooks.py index fe5c21c..0f9dbe2 100644 --- a/tests/unit/objects/test_hooks.py +++ b/tests/unit/objects/test_hooks.py @@ -1,29 +1,209 @@ """ GitLab API: https://docs.gitlab.com/ce/api/system_hooks.html +GitLab API: https://docs.gitlab.com/ce/api/groups.html#hooks +GitLab API: https://docs.gitlab.com/ee/api/projects.html#hooks """ + +import re + import pytest import responses -from gitlab.v4.objects import Hook +from gitlab.v4.objects import GroupHook, Hook, ProjectHook + +hooks_content = [ + { + "id": 1, + "url": "testurl", + "push_events": True, + "tag_push_events": True, + }, + { + "id": 2, + "url": "testurl_second", + "push_events": False, + "tag_push_events": False, + }, +] + +hook_content = hooks_content[0] + + +@pytest.fixture +def resp_hooks_list(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url=re.compile(r"http://localhost/api/v4/((groups|projects)/1/|)hooks"), + json=hooks_content, + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_hook_get(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url=re.compile(r"http://localhost/api/v4/((groups|projects)/1/|)hooks/1"), + json=hook_content, + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_hook_create(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.POST, + url=re.compile(r"http://localhost/api/v4/((groups|projects)/1/|)hooks"), + json=hook_content, + content_type="application/json", + status=200, + ) + yield rsps @pytest.fixture -def resp_get_hook(): - content = {"url": "testurl", "id": 1} +def resp_hook_update(): + with responses.RequestsMock() as rsps: + pattern = re.compile(r"http://localhost/api/v4/((groups|projects)/1/|)hooks/1") + rsps.add( + method=responses.GET, + url=pattern, + json=hook_content, + content_type="application/json", + status=200, + ) + rsps.add( + method=responses.PUT, + url=pattern, + json=hook_content, + content_type="application/json", + status=200, + ) + yield rsps + +@pytest.fixture +def resp_hook_delete(): with responses.RequestsMock() as rsps: + pattern = re.compile(r"http://localhost/api/v4/((groups|projects)/1/|)hooks/1") rsps.add( method=responses.GET, - url="http://localhost/api/v4/hooks/1", - json=content, + url=pattern, + json=hook_content, content_type="application/json", status=200, ) + rsps.add( + method=responses.DELETE, + url=pattern, + status=204, + ) yield rsps -def test_hooks(gl, resp_get_hook): +def test_list_system_hooks(gl, resp_hooks_list): + hooks = gl.hooks.list() + assert hooks[0].id == 1 + assert hooks[0].url == "testurl" + assert hooks[1].id == 2 + assert hooks[1].url == "testurl_second" + + +def test_get_system_hook(gl, resp_hook_get): data = gl.hooks.get(1) assert isinstance(data, Hook) assert data.url == "testurl" assert data.id == 1 + + +def test_create_system_hook(gl, resp_hook_create): + hook = gl.hooks.create(hook_content) + assert hook.url == "testurl" + assert hook.push_events is True + assert hook.tag_push_events is True + + +# there is no update method for system hooks + + +def test_delete_system_hook(gl, resp_hook_delete): + hook = gl.hooks.get(1) + hook.delete() + gl.hooks.delete(1) + + +def test_list_group_hooks(group, resp_hooks_list): + hooks = group.hooks.list() + assert hooks[0].id == 1 + assert hooks[0].url == "testurl" + assert hooks[1].id == 2 + assert hooks[1].url == "testurl_second" + + +def test_get_group_hook(group, resp_hook_get): + data = group.hooks.get(1) + assert isinstance(data, GroupHook) + assert data.url == "testurl" + assert data.id == 1 + + +def test_create_group_hook(group, resp_hook_create): + hook = group.hooks.create(hook_content) + assert hook.url == "testurl" + assert hook.push_events is True + assert hook.tag_push_events is True + + +def test_update_group_hook(group, resp_hook_update): + hook = group.hooks.get(1) + assert hook.id == 1 + hook.url = "testurl_more" + hook.save() + + +def test_delete_group_hook(group, resp_hook_delete): + hook = group.hooks.get(1) + hook.delete() + group.hooks.delete(1) + + +def test_list_project_hooks(project, resp_hooks_list): + hooks = project.hooks.list() + assert hooks[0].id == 1 + assert hooks[0].url == "testurl" + assert hooks[1].id == 2 + assert hooks[1].url == "testurl_second" + + +def test_get_project_hook(project, resp_hook_get): + data = project.hooks.get(1) + assert isinstance(data, ProjectHook) + assert data.url == "testurl" + assert data.id == 1 + + +def test_create_project_hook(project, resp_hook_create): + hook = project.hooks.create(hook_content) + assert hook.url == "testurl" + assert hook.push_events is True + assert hook.tag_push_events is True + + +def test_update_project_hook(project, resp_hook_update): + hook = project.hooks.get(1) + assert hook.id == 1 + hook.url = "testurl_more" + hook.save() + + +def test_delete_project_hook(project, resp_hook_delete): + hook = project.hooks.get(1) + hook.delete() + project.hooks.delete(1) diff --git a/tests/unit/objects/test_projects.py b/tests/unit/objects/test_projects.py index 73e119b..039d5ec 100644 --- a/tests/unit/objects/test_projects.py +++ b/tests/unit/objects/test_projects.py @@ -178,31 +178,6 @@ def test_delete_shared_project_link(gl): @pytest.mark.skip(reason="missing test") -def test_list_project_hooks(gl): - pass - - -@pytest.mark.skip(reason="missing test") -def test_get_project_hook(gl): - pass - - -@pytest.mark.skip(reason="missing test") -def test_create_project_hook(gl): - pass - - -@pytest.mark.skip(reason="missing test") -def test_update_project_hook(gl): - pass - - -@pytest.mark.skip(reason="missing test") -def test_delete_project_hook(gl): - pass - - -@pytest.mark.skip(reason="missing test") def test_create_forked_from_relationship(gl): pass |
