|
9 | 9 | import pytest
|
10 | 10 | import responses
|
11 | 11 |
|
| 12 | +import gitlab |
12 | 13 | from gitlab.v4.objects import GroupHook, Hook, ProjectHook
|
13 | 14 |
|
14 | 15 | hooks_content = [
|
@@ -89,6 +90,58 @@ def resp_hook_update():
|
89 | 90 | yield rsps
|
90 | 91 |
|
91 | 92 |
|
| 93 | +@pytest.fixture |
| 94 | +def resp_hook_test(): |
| 95 | + with responses.RequestsMock() as rsps: |
| 96 | + hook_pattern = re.compile( |
| 97 | + r"http://localhost/api/v4/((groups|projects)/1/|)hooks/1" |
| 98 | + ) |
| 99 | + test_pattern = re.compile( |
| 100 | + r"http://localhost/api/v4/((groups|projects)/1/|)hooks/1/test/[a-z_]+" |
| 101 | + ) |
| 102 | + rsps.add( |
| 103 | + method=responses.GET, |
| 104 | + url=hook_pattern, |
| 105 | + json=hook_content, |
| 106 | + content_type="application/json", |
| 107 | + status=200, |
| 108 | + ) |
| 109 | + rsps.add( |
| 110 | + method=responses.POST, |
| 111 | + url=test_pattern, |
| 112 | + json={"message": "201 Created"}, |
| 113 | + content_type="application/json", |
| 114 | + status=201, |
| 115 | + ) |
| 116 | + yield rsps |
| 117 | + |
| 118 | + |
| 119 | +@pytest.fixture |
| 120 | +def resp_hook_test_error(): |
| 121 | + with responses.RequestsMock() as rsps: |
| 122 | + hook_pattern = re.compile( |
| 123 | + r"http://localhost/api/v4/((groups|projects)/1/|)hooks/1" |
| 124 | + ) |
| 125 | + test_pattern = re.compile( |
| 126 | + r"http://localhost/api/v4/((groups|projects)/1/|)hooks/1/test/[a-z_]+" |
| 127 | + ) |
| 128 | + rsps.add( |
| 129 | + method=responses.GET, |
| 130 | + url=hook_pattern, |
| 131 | + json=hook_content, |
| 132 | + content_type="application/json", |
| 133 | + status=200, |
| 134 | + ) |
| 135 | + rsps.add( |
| 136 | + method=responses.POST, |
| 137 | + url=test_pattern, |
| 138 | + json={"message": "<html>error</html>"}, |
| 139 | + content_type="application/json", |
| 140 | + status=422, |
| 141 | + ) |
| 142 | + yield rsps |
| 143 | + |
| 144 | + |
92 | 145 | @pytest.fixture
|
93 | 146 | def resp_hook_delete():
|
94 | 147 | with responses.RequestsMock() as rsps:
|
@@ -174,6 +227,17 @@ def test_delete_group_hook(group, resp_hook_delete):
|
174 | 227 | group.hooks.delete(1)
|
175 | 228 |
|
176 | 229 |
|
| 230 | +def test_test_group_hook(group, resp_hook_test): |
| 231 | + hook = group.hooks.get(1) |
| 232 | + hook.test("push_events") |
| 233 | + |
| 234 | + |
| 235 | +def test_test_error_group_hook(group, resp_hook_test_error): |
| 236 | + hook = group.hooks.get(1) |
| 237 | + with pytest.raises(gitlab.exceptions.GitlabHookTestError): |
| 238 | + hook.test("push_events") |
| 239 | + |
| 240 | + |
177 | 241 | def test_list_project_hooks(project, resp_hooks_list):
|
178 | 242 | hooks = project.hooks.list()
|
179 | 243 | assert hooks[0].id == 1
|
|
0 commit comments