|
|
import unittest |
|
|
from unittest.mock import patch, MagicMock |
|
|
from app import processar_texto, chat_inteligente |
|
|
|
|
|
class TestIntegration(unittest.TestCase): |
|
|
@patch('app.nlu.analyze') |
|
|
def test_processar_texto_mock(self, mock_analyze): |
|
|
|
|
|
mock_resumo = {'summarization': {'text': 'Este é um resumo.'}} |
|
|
mock_topicos = {'keywords': [{'text': 'ia'}, {'text': 'tecnologia'}]} |
|
|
mock_classificacao = {'categories': [{'label': '/technology'}]} |
|
|
|
|
|
mock_analyze.side_effect = [ |
|
|
MagicMock(get_result=lambda: mock_resumo), |
|
|
MagicMock(get_result=lambda: mock_topicos), |
|
|
MagicMock(get_result=lambda: mock_classificacao) |
|
|
] |
|
|
|
|
|
resumo, topicos, classificacao = processar_texto("Texto de teste com tamanho suficiente.") |
|
|
|
|
|
self.assertEqual(resumo, "Este é um resumo.") |
|
|
self.assertIn("ia", topicos) |
|
|
self.assertIn("/technology", classificacao) |
|
|
|
|
|
@patch('app.obter_iam_token') |
|
|
@patch('app.requests.post') |
|
|
def test_chat_inteligente_mock(self, mock_post, mock_token): |
|
|
mock_token.return_value = "fake_token" |
|
|
|
|
|
mock_response = MagicMock() |
|
|
mock_response.status_code = 200 |
|
|
mock_response.json.return_value = { |
|
|
'choices': [{'message': {'content': 'Resposta mockada da IA.'}}] |
|
|
} |
|
|
mock_post.return_value = mock_response |
|
|
|
|
|
resposta = chat_inteligente("Qual o tema?", "O documento fala sobre IA.") |
|
|
self.assertEqual(resposta, "Resposta mockada da IA.") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
unittest.main() |
|
|
|