mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 04:12:23 +01:00
54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
from typing import Type, cast
|
|
|
|
from ee.api.test.base import APILicensedTest
|
|
from ee.clickhouse.util import ClickhouseTestMixin
|
|
from ee.models.hook import Hook
|
|
|
|
|
|
class TestHooksAPI(ClickhouseTestMixin, APILicensedTest):
|
|
def test_create_hook(self):
|
|
data = {"target": "https://hooks.example.com/abcd/", "event": "annotation_created"}
|
|
response = self.client.post(f"/api/projects/{self.team.id}/hooks/", data)
|
|
self.assertEqual(response.status_code, 201)
|
|
hook: Type[Hook] = Hook.objects.first()
|
|
self.assertEqual(hook.team, self.team)
|
|
self.assertEqual(hook.target, data["target"])
|
|
self.assertEqual(hook.event, data["event"])
|
|
self.assertEqual(hook.resource_id, None)
|
|
self.assertDictContainsSubset(
|
|
{
|
|
"id": hook.id,
|
|
"event": data["event"],
|
|
"target": data["target"],
|
|
"resource_id": None,
|
|
"team": self.team.id,
|
|
},
|
|
cast(dict, response.json()),
|
|
)
|
|
|
|
def test_create_hook_with_resource_id(self):
|
|
data = {"target": "https://hooks.example.com/abcd/", "event": "annotation_created", "resource_id": "66"}
|
|
response = self.client.post(f"/api/projects/{self.team.id}/hooks/", data)
|
|
self.assertEqual(response.status_code, 201)
|
|
hook: Type[Hook] = Hook.objects.first()
|
|
self.assertEqual(hook.team, self.team)
|
|
self.assertEqual(hook.target, data["target"])
|
|
self.assertEqual(hook.event, data["event"])
|
|
self.assertEqual(str(hook.resource_id), data["resource_id"])
|
|
self.assertDictContainsSubset(
|
|
{
|
|
"id": hook.id,
|
|
"event": data["event"],
|
|
"target": data["target"],
|
|
"resource_id": int(data["resource_id"]),
|
|
"team": self.team.id,
|
|
},
|
|
cast(dict, response.json()),
|
|
)
|
|
|
|
def test_delete_hook(self):
|
|
hook_id = "abc123"
|
|
Hook.objects.create(id=hook_id, user=self.user, team=self.team, resource_id=20)
|
|
response = self.client.delete(f"/api/projects/{self.team.id}/hooks/{hook_id}")
|
|
self.assertEqual(response.status_code, 204)
|