Files
Odoo-Modules/fusion_accounting_reports/tests/test_commentary_prompt.py
2026-04-19 15:30:28 -04:00

51 lines
2.0 KiB
Python

"""Tests for commentary_prompt module."""
from odoo.tests.common import TransactionCase, tagged
from odoo.addons.fusion_accounting_reports.services.commentary_prompt import (
SYSTEM_PROMPT, build_prompt,
)
@tagged('post_install', '-at_install')
class TestCommentaryPrompt(TransactionCase):
def test_system_prompt_requires_json(self):
self.assertIn('JSON', SYSTEM_PROMPT)
self.assertIn('"summary"', SYSTEM_PROMPT)
self.assertIn('"highlights"', SYSTEM_PROMPT)
def test_build_prompt_returns_tuple(self):
report = {'report_name': 'P&L', 'period': {'label': 'Apr 2026',
'date_from': '2026-04-01',
'date_to': '2026-04-30'},
'rows': []}
result = build_prompt(report, [])
self.assertEqual(len(result), 2)
self.assertIn('REPORT', result[1])
self.assertIn('Apr 2026', result[1])
def test_user_prompt_includes_rows(self):
report = {
'report_name': 'P&L',
'period': {'label': 'X', 'date_from': 'a', 'date_to': 'b'},
'rows': [
{'id': 'r1', 'label': 'Revenue', 'amount': 100000.50},
{'id': 'r2', 'label': 'Net Income', 'amount': 25000, 'is_subtotal': True},
],
}
_, user = build_prompt(report, [])
self.assertIn('Revenue', user)
self.assertIn('100,000.50', user)
self.assertIn('SUBTOTAL', user)
def test_user_prompt_includes_anomalies(self):
report = {'report_name': 'X', 'period': {'label': 'X', 'date_from': '', 'date_to': ''}, 'rows': []}
anomalies = [
{'label': 'Revenue', 'direction': 'increase', 'variance_pct': 25.0,
'variance_amount': 5000, 'severity': 'medium'},
]
_, user = build_prompt(report, anomalies)
self.assertIn('ANOMALIES', user)
self.assertIn('Revenue', user)
self.assertIn('25.0%', user)