Skip to content

Commit 403d252

Browse files
author
Costin Bleotu
committed
Test hooks list and delete.
1 parent 95e368d commit 403d252

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

gogs_client/interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ def delete_hook(self, auth, username, repo_name, hook_id):
366366
:raises ApiFailure: if the request cannot be serviced
367367
"""
368368
path = "/repos/{u}/{r}/hooks/{i}".format(u=username, r=repo_name, i=hook_id)
369-
self._check_ok(self._delete(path, auth=auth))
369+
response = self._check_ok(self._delete(path, auth=auth))
370+
return response
370371

371372
# Helper methods
372373

tests/interface_test.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,38 @@ def setUp(self):
6565
"updated_at": "2017-03-31T12:42:58Z",
6666
"created_at": "2017-03-31T12:42:58Z"
6767
}"""
68-
68+
self.hooks_list_json_str = """[
69+
{
70+
"id": 4,
71+
"type": "gogs",
72+
"config": {
73+
"content_type": "json",
74+
"url": "http://test.io/hook"
75+
},
76+
"events": [
77+
"create",
78+
"push",
79+
"issues"
80+
],
81+
"active": false,
82+
"updated_at": "2017-03-31T12:42:58Z",
83+
"created_at": "2017-03-31T12:42:58Z"
84+
},
85+
{
86+
"id": 3,
87+
"type": "gogs",
88+
"config": {
89+
"content_type": "json",
90+
"url": "http://192.168.201.1:8080/hook22/"
91+
},
92+
"events": [
93+
"issue_comment"
94+
],
95+
"active": true,
96+
"updated_at": "2017-03-31T12:47:56Z",
97+
"created_at": "2017-03-31T12:42:54Z"
98+
}
99+
]"""
69100
self.expected_repo = gogs_client.GogsRepo.from_json(json.loads(self.repo_json_str))
70101
self.expected_user = gogs_client.GogsUser.from_json(json.loads(self.user_json_str))
71102
self.expected_hook = gogs_client.GogsRepo.Hook.from_json(json.loads(self.hook_json_str))
@@ -323,6 +354,20 @@ def callback(request):
323354
hook = self.client.update_hook(self.token, "repo1", 4, update, organization="username")
324355
self.assert_hooks_equals(hook, self.expected_hook)
325356

357+
@responses.activate
358+
def test_list_hooks(self):
359+
uri = self.path("/repos/username/repo1/hooks")
360+
responses.add(responses.GET, uri, body=self.hooks_list_json_str, status=20)
361+
hooks = self.client.get_repo_hooks(self.token, "username", "repo1")
362+
self.assertEqual(len(hooks), 2)
363+
self.assert_hooks_equals(hooks[0], self.expected_hook)
364+
365+
@responses.activate
366+
def test_delete_hook(self):
367+
uri = self.path("/repos/username/repo1/hooks/4")
368+
responses.add(responses.DELETE, uri, status=204)
369+
hook = self.client.delete_hook(self.token, "username", "repo1", 4)
370+
self.assertEqual(hook.status_code, 204)
326371

327372
# helper methods
328373

0 commit comments

Comments
 (0)