0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-29 02:46:32 +01:00
posthog/ee/tasks/test/test_webhooks_ee.py
Michael Matloka 96e4ee8512
Nest endpoints of project-based models under /api/project/ – LITE (#2485)
* Nest endpoints under /project/ with StructuredViewSetMixin

* Rewrite URLs

* isort

* Update utils.py

* Fix errors

* Fix almoast all the errors

Last left to do: shared dashboards and permission classes.

* isort

* Adjust for master

* Add compatbility with shared dashboards

* Debug ClickHouse

* Remove some # type: ignores

* Simplify CursorPagination

* Move test base from posthog.api.test to posthog.test

* Improve API structure

* Bring back legacy endpoints

* Fix legacy compatibility

* Fix bugs and typing

* isort

* Fix hooks test

* Try fixing errors

* Fix oversight

* isort

* Fix problems

* isort

* Be more tolerant

* Fix naming and remove redundant code

* Fix imports

* Update deleteWithUndo

* Roll back

* Roll back more

* Update .gitignore

* Rollll back

* Rollllllll

* back

* Betterify

* Address feedback
2020-11-24 23:26:28 +01:00

47 lines
1.4 KiB
Python

from unittest.mock import call, patch
import pytz
from django.utils.timezone import now
from ee.tasks.webhooks_ee import post_event_to_webhook_ee
from posthog.models.action import Action
from posthog.models.action_step import ActionStep
from posthog.models.event import Event
from posthog.test.base import BaseTest
def _create_action(**kwargs):
team = kwargs.pop("team")
name = kwargs.pop("name")
post_to_slack = kwargs.pop("post_to_slack")
action = Action.objects.create(team=team, name=name, post_to_slack=post_to_slack)
ActionStep.objects.create(action=action, event=name)
return action
class TestWebhooksEE(BaseTest):
@patch("requests.post")
def test_post_event_to_webhook_ee(self, requests_post):
self.team.slack_incoming_webhook = "http://slack.com/hook"
self.team.save()
_create_action(team=self.team, name="user paid", post_to_slack=True)
_create_action(team=self.team, name="user not paid", post_to_slack=True)
_now = now()
event = {
"event": "user paid",
"properties": {},
"distinct_id": "test",
"timestamp": _now,
"elements_list": {},
}
site_url = "http://testserver"
post_event_to_webhook_ee(event, self.team.pk, site_url)
self.assertEqual(requests_post.call_count, 1)
events = Event.objects.filter(event="User paid")
self.assertEqual(list(events), [])