Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meikelmosby committed Jan 31, 2025
1 parent 43e42b4 commit 0c1a2a4
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions posthog/api/test/test_hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,25 +1285,8 @@ def test_transformation_functions_require_template_when_disabled(self):

@override_settings(HOG_TRANSFORMATIONS_ENABLED=False)
def test_transformation_functions_preserve_template_code_when_disabled(self):
# Create a proper mock template class
class MockTemplate:
id = "test-template"
name = "Test Template"
type = "transformation"
description = "Test template description"
status = "free"
inputs_schema = []
hog = "return event"
icon_url = None
category = None
filters = None
masking = None
mappings = None
mapping_templates = None
sub_templates = None

with patch("posthog.api.hog_function_template.HogFunctionTemplates.template") as mock_template:
mock_template.return_value = MockTemplate()
mock_template.return_value = template_slack # Use existing template instead of creating mock

# First create with transformations enabled
with override_settings(HOG_TRANSFORMATIONS_ENABLED=True):
Expand All @@ -1312,8 +1295,12 @@ class MockTemplate:
data={
"name": "Template Transform",
"type": "transformation",
"template_id": "test-template",
"hog": "return event",
"template_id": template_slack.id,
"hog": "return modified_event",
"inputs": {
"slack_workspace": {"value": 1},
"channel": {"value": "#general"},
},
},
)
assert response.status_code == status.HTTP_201_CREATED, response.json()
Expand All @@ -1323,9 +1310,9 @@ class MockTemplate:
response = self.client.patch(
f"/api/projects/{self.team.id}/hog_functions/{function_id}/",
data={
"hog": "return modified_event",
"hog": "return another_event",
},
)

assert response.status_code == status.HTTP_200_OK
assert response.json()["hog"] == "return event" # Original code preserved
assert response.json()["hog"] == template_slack.hog # Original template code preserved

0 comments on commit 0c1a2a4

Please sign in to comment.