Increase security and reformat
This commit is contained in:
@@ -35,7 +35,9 @@ class BPSubcommandTests(TransactionTestCase):
|
||||
service="whatsapp",
|
||||
identifier="120363402761690215",
|
||||
)
|
||||
self.session = ChatSession.objects.create(user=self.user, identifier=self.identifier)
|
||||
self.session = ChatSession.objects.create(
|
||||
user=self.user, identifier=self.identifier
|
||||
)
|
||||
self.profile = CommandProfile.objects.create(
|
||||
user=self.user,
|
||||
slug="bp",
|
||||
@@ -96,13 +98,19 @@ class BPSubcommandTests(TransactionTestCase):
|
||||
source_service="whatsapp",
|
||||
source_chat_id="120363402761690215",
|
||||
)
|
||||
with patch("core.commands.handlers.bp.ai_runner.run_prompt", new=AsyncMock()) as mocked_ai:
|
||||
result = async_to_sync(BPCommandHandler().execute)(self._ctx(trigger, trigger.text))
|
||||
with patch(
|
||||
"core.commands.handlers.bp.ai_runner.run_prompt", new=AsyncMock()
|
||||
) as mocked_ai:
|
||||
result = async_to_sync(BPCommandHandler().execute)(
|
||||
self._ctx(trigger, trigger.text)
|
||||
)
|
||||
self.assertTrue(result.ok)
|
||||
mocked_ai.assert_not_awaited()
|
||||
doc = BusinessPlanDocument.objects.get(trigger_message=trigger)
|
||||
self.assertEqual("direct body", doc.content_markdown)
|
||||
self.assertEqual("Generated from 1 message.", doc.structured_payload.get("annotation"))
|
||||
self.assertEqual(
|
||||
"Generated from 1 message.", doc.structured_payload.get("annotation")
|
||||
)
|
||||
|
||||
def test_set_reply_only_uses_anchor(self):
|
||||
anchor = Message.objects.create(
|
||||
@@ -124,11 +132,15 @@ class BPSubcommandTests(TransactionTestCase):
|
||||
source_chat_id="120363402761690215",
|
||||
reply_to=anchor,
|
||||
)
|
||||
result = async_to_sync(BPCommandHandler().execute)(self._ctx(trigger, trigger.text))
|
||||
result = async_to_sync(BPCommandHandler().execute)(
|
||||
self._ctx(trigger, trigger.text)
|
||||
)
|
||||
self.assertTrue(result.ok)
|
||||
doc = BusinessPlanDocument.objects.get(trigger_message=trigger)
|
||||
self.assertEqual("anchor body", doc.content_markdown)
|
||||
self.assertEqual("Generated from 1 message.", doc.structured_payload.get("annotation"))
|
||||
self.assertEqual(
|
||||
"Generated from 1 message.", doc.structured_payload.get("annotation")
|
||||
)
|
||||
|
||||
def test_set_reply_plus_addendum_uses_divider(self):
|
||||
anchor = Message.objects.create(
|
||||
@@ -150,7 +162,9 @@ class BPSubcommandTests(TransactionTestCase):
|
||||
source_chat_id="120363402761690215",
|
||||
reply_to=anchor,
|
||||
)
|
||||
result = async_to_sync(BPCommandHandler().execute)(self._ctx(trigger, trigger.text))
|
||||
result = async_to_sync(BPCommandHandler().execute)(
|
||||
self._ctx(trigger, trigger.text)
|
||||
)
|
||||
self.assertTrue(result.ok)
|
||||
doc = BusinessPlanDocument.objects.get(trigger_message=trigger)
|
||||
self.assertIn("base body", doc.content_markdown)
|
||||
@@ -171,7 +185,9 @@ class BPSubcommandTests(TransactionTestCase):
|
||||
source_service="whatsapp",
|
||||
source_chat_id="120363402761690215",
|
||||
)
|
||||
result = async_to_sync(BPCommandHandler().execute)(self._ctx(trigger, trigger.text))
|
||||
result = async_to_sync(BPCommandHandler().execute)(
|
||||
self._ctx(trigger, trigger.text)
|
||||
)
|
||||
self.assertFalse(result.ok)
|
||||
self.assertEqual("failed", result.status)
|
||||
self.assertEqual("bp_set_range_requires_reply_target", result.error)
|
||||
@@ -205,8 +221,12 @@ class BPSubcommandTests(TransactionTestCase):
|
||||
source_chat_id="120363402761690215",
|
||||
reply_to=anchor,
|
||||
)
|
||||
result = async_to_sync(BPCommandHandler().execute)(self._ctx(trigger, trigger.text))
|
||||
result = async_to_sync(BPCommandHandler().execute)(
|
||||
self._ctx(trigger, trigger.text)
|
||||
)
|
||||
self.assertTrue(result.ok)
|
||||
doc = BusinessPlanDocument.objects.get(trigger_message=trigger)
|
||||
self.assertEqual("line 1\n(no text)\n#bp set range#", doc.content_markdown)
|
||||
self.assertEqual("Generated from 3 messages.", doc.structured_payload.get("annotation"))
|
||||
self.assertEqual(
|
||||
"Generated from 3 messages.", doc.structured_payload.get("annotation")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user