Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Jul 25, 2024
1 parent 0bf3629 commit 83b1e10
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion posthog/api/test/test_hog_function.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Optional
from typing import Any, Optional
from unittest.mock import ANY, patch

from rest_framework import status
Expand Down Expand Up @@ -552,3 +552,62 @@ def test_patches_status_on_enabled_update(self, *args):
f"http://localhost:6738/api/projects/{self.team.id}/hog_functions/{response.json()['id']}/status",
json={"state": 2},
)

@patch("posthog.permissions.posthoganalytics.feature_enabled", return_value=True)
def test_list_with_filters_filter(self, *args):
action1 = Action.objects.create(
team=self.team,
name="test action",
steps_json=[{"event": "$pageview", "url": "docs", "url_matching": "contains"}],
)

action2 = Action.objects.create(
team=self.team,
name="test action",
steps_json=[{"event": "$pageview", "url": "docs", "url_matching": "contains"}],
)

self.team.test_account_filters = [
{
"key": "email",
"value": "@posthog.com",
"operator": "not_icontains",
"type": "person",
}
]
self.team.save()
response = self.client.post(
f"/api/projects/{self.team.id}/hog_functions/",
data={
**EXAMPLE_FULL,
"filters": {
"events": [{"id": "$pageview", "name": "$pageview", "type": "events", "order": 0}],
"actions": [
{"id": f"{action1.id}", "name": "Test Action", "type": "actions", "order": 1},
{"id": f"{action2.id}", "name": "Test Action", "type": "actions", "order": 1},
],
"filter_test_accounts": True,
},
},
)
assert response.status_code == status.HTTP_201_CREATED, response.json()

filters: Any = {"filter_test_accounts": True}
response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}")
assert len(response.json()["results"]) == 1

filters = {"filter_test_accounts": False}
response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}")
assert len(response.json()["results"]) == 0

filters = {"actions": [{"id": f"other"}]}
response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}")
assert len(response.json()["results"]) == 0

filters = {"actions": [{"id": f"{action1.id}"}]}
response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}")
assert len(response.json()["results"]) == 1

filters = {"actions": [{"id": f"{action2.id}"}]}
response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}")
assert len(response.json()["results"]) == 1

0 comments on commit 83b1e10

Please sign in to comment.