0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 09:14:46 +01:00
posthog/ee/hogai/trends/test/test_nodes.py

40 lines
1.4 KiB
Python
Raw Normal View History

from unittest.mock import patch
from django.test import override_settings
from langchain_core.runnables import RunnableLambda
from ee.hogai.trends.nodes import TrendsGeneratorNode, TrendsSchemaGeneratorOutput
from posthog.schema import (
AssistantTrendsQuery,
HumanMessage,
VisualizationMessage,
)
from posthog.test.base import APIBaseTest, ClickhouseTestMixin
@override_settings(IN_UNIT_TESTING=True)
class TestTrendsGeneratorNode(ClickhouseTestMixin, APIBaseTest):
def setUp(self):
self.schema = AssistantTrendsQuery(series=[])
def test_node_runs(self):
node = TrendsGeneratorNode(self.team)
with patch.object(TrendsGeneratorNode, "_model") as generator_model_mock:
generator_model_mock.return_value = RunnableLambda(
lambda _: TrendsSchemaGeneratorOutput(reasoning_steps=["step"], answer=self.schema).model_dump()
)
new_state = node.run(
{
"messages": [HumanMessage(content="Text")],
"plan": "Plan",
},
{},
)
self.assertEqual(
new_state,
{
"messages": [VisualizationMessage(answer=self.schema, plan="Plan", reasoning_steps=["step"])],
"intermediate_steps": None,
},
)