File size: 3,004 Bytes
411f252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Tests for the TutorX MCP server
"""

import sys
import os
import unittest
import json
from datetime import datetime
from unittest.mock import patch, MagicMock

# Add parent directory to path to import modules
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from main import assess_skill, generate_quiz, get_concept_graph


class TestMCPServer(unittest.TestCase):
    """Test cases for the TutorX MCP server"""

    def setUp(self):
        """Set up test fixtures"""
        self.student_id = "test_student_123"
        self.concept_id = "math_algebra_basics"
        
    def test_assess_skill(self):
        """Test assess_skill tool"""
        result = assess_skill(self.student_id, self.concept_id)
        
        # Verify the structure of the result
        self.assertIsInstance(result, dict)
        self.assertEqual(result["student_id"], self.student_id)
        self.assertEqual(result["concept_id"], self.concept_id)
        self.assertIsInstance(result["skill_level"], float)
        self.assertIsInstance(result["confidence"], float)
        self.assertIsInstance(result["recommendations"], list)
        self.assertIn("timestamp", result)
        
    def test_generate_quiz(self):
        """Test generate_quiz tool"""
        concept_ids = [self.concept_id]
        difficulty = 2
        
        result = generate_quiz(concept_ids, difficulty)
        
        # Verify the structure of the result
        self.assertIsInstance(result, dict)
        self.assertIn("quiz_id", result)
        self.assertEqual(result["concept_ids"], concept_ids)
        self.assertEqual(result["difficulty"], difficulty)
        self.assertIsInstance(result["questions"], list)
        self.assertGreater(len(result["questions"]), 0)
        
        # Check question structure
        question = result["questions"][0]
        self.assertIn("id", question)
        self.assertIn("text", question)
        self.assertIn("type", question)
        self.assertIn("answer", question)
        self.assertIn("solution_steps", question)
        
    def test_get_concept_graph(self):
        """Test get_concept_graph resource"""
        result = get_concept_graph()
        
        # Verify the structure of the result
        self.assertIsInstance(result, dict)
        self.assertIn("nodes", result)
        self.assertIn("edges", result)
        self.assertIsInstance(result["nodes"], list)
        self.assertIsInstance(result["edges"], list)
        self.assertGreater(len(result["nodes"]), 0)
        self.assertGreater(len(result["edges"]), 0)
        
        # Check node structure
        node = result["nodes"][0]
        self.assertIn("id", node)
        self.assertIn("name", node)
        self.assertIn("difficulty", node)
        
        # Check edge structure
        edge = result["edges"][0]
        self.assertIn("from", edge)
        self.assertIn("to", edge)
        self.assertIn("weight", edge)


if __name__ == "__main__":
    unittest.main()