File size: 1,607 Bytes
e34be6c
 
 
 
 
 
 
1543ec3
e34be6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from unittest import TestCase
from unittest.mock import MagicMock, patch

from edu_assistant.learning_tasks import CodingProblemAnalysis


class TestCodingProblemAnalysis(TestCase):
    @patch.object(CodingProblemAnalysis, "_init_llm", MagicMock())
    def setUp(self):
        self.analysis = CodingProblemAnalysis()

    @patch.object(
        CodingProblemAnalysis,
        "_build_chain",
        return_value=MagicMock(return_value={"response": "Expected Result"}),
    )
    def test_start_analysis(self, mock_chain):
        problem = MagicMock()
        answer = MagicMock()
        result = self.analysis.start_analysis(problem, answer, "First question")

        self.assertIn("session_id", result)
        self.assertIn("response", result)
        self.assertEqual(result["response"], "Expected Result")
        mock_chain.assert_called_once_with(problem, answer)

    @patch.object(
        CodingProblemAnalysis,
        "_build_chain",
        return_value=MagicMock(return_value={"response": "Expected Result"}),
    )
    def test_ask(self, mock_chain):
        session_id = self.analysis.start_analysis(MagicMock(), MagicMock(), "First question")["session_id"]
        result = self.analysis.ask("New question", session_id)
        self.assertIn("session_id", result)
        self.assertIn("response", result)
        self.assertEqual(result["response"], "Expected Result")
        self.assertEqual(result["session_id"], session_id)
        self.analysis._session_store[session_id].has_calls(2)
        self.analysis._session_store[session_id].assert_called_with({"input": "New question"})